use strict; ## IMPORTANT!!! use warnings; ## IMPORTANT!!! use autodie; ## IMPORTANT!!! use Cwd qw/ cwd /; our $startingDir = cwd(); ... for my $dir( @dirs ){ chdir $dir; # autodie makes this die on error print cwd(), "\n"; chdir $startingDir; }