use File::chdir; my $wd = $CWD; chdir('subdir'); # do some work. $CWD = $wd; # return to saved dir.