if ($foo) { local $cwd = ".."; /* current working directory changes */ ... } /* cwd is back to original directory */