Question: I am trying to chdir in perl but I am just not able to get my head around what's going wrong.
This code works.

```
chdir('C:\Users\Server\Desktop')

```

But when trying to get the user's input, it doesn't work. I even tried using chomp to remove any spaces that might come.

```
print "Please enter the directory\n";
$p=<STDIN>;
chdir ('$p') or die "sorry";
system("dir");

```

Also could someone please explain how I could use the system command in this same situation and how it differs from chdir. 

The final aim is to access two folders, check for files that are named the same (eg: if both the folders have a file named "water") and copy the file that has the same name into a third folder.

Answer: 
`chdir('$p')` tries to change to a directory literally named `$p`. Drop the single quotes:

```
chdir($p)

```

Also, after reading it in, you probably want to remove the newline (unless the directory name really does end with a newline):

```
$p = <STDIN>;
chomp($p);

```

But if you are just chdiring to be able to run `dir` and get the results in your script, you probably don't want to do that. First of all, system runs a command but doesn't capture its output. Secondly, you can just do:

```
opendir my $dirhandle, $p or die "unable to open directory $p: $!\n";
my @files = readdir $dirhandle;
closedir $dirhandle;

```

and avoid the chdir and running a command prompt command altogether.
I will use it this way.

chdir "C:/Users/Server/Desktop"

The above works for me