sub foo { my $dir = shift; chdir $dir; local *CURRENT_DIR; # Everything else follows }