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 ); }