use strict; ## IMPORTANT!!! use warnings; ## IMPORTANT!!! use File::Tools qw/ pushd popd /; use Cwd qw/ cwd /; ... for my $dir( @dirs ){ pushd( $dir ); print cwd(), "\n"; popd( $dir ); } #### 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; }