use strict; use warnings; use Cwd; my $dir = shift; chdir $dir or die "Couldn't chdir $dir: $!\n"; print "OK, in ". getcwd . "\n"; #### # ./change.pl Downloads/ OK, in /home/Random/Downloads # ./perl change.pl foo Couldn't chdir foo: No such file or directory # ./mkdir bar # ./chmod 000 bar # ./perl change.pl bar Couldn't chdir bar: Permission denied