use Cwd; use File::pushd; print cwd; { my $dir = pushd('subdir'); print join("\n", glob '*'); } # back where we started print cwd; print join("\n", glob '*'); #### use File::pushd; { my $wd = pushd(); chdir('subdir'); # do some work. } # automatically back in original dir #### use File::pushd; { my $wd = tempd(); # do work in the temporary directory } # back in the original directory and the temporary directory is deleted