in reply to Controlling the directory location on exit.

No.

It's not Perl restoring it. Rather, the change was made in Perl's own copy of the environment, and that vanished when Perl exited. The shell (or other program) that launched perl.exe never sees the change, and fundimentally cannot.

In the DOS days, there was a way to do it by finding the root environment block.

Doing this is not a capability of the OS. Instead, a specific way would be needed to communicate to the parent process and tell it to change its own local copy. I don't know if any popular command shell does this. It would be possible in the Explorer GUI shell using an add-in that runs inproc.

What I've thought about is having the program not change directories itself (which as you know is pointless) but communicate the new directory name back to the caller somehow. Then, run that from a BAT file (which can change directories).

Example,

REM this is fancyCD.BAT echo "chdir " > temp.bat fancyCD.pl >> temp.bat temp
Where the perl script writes the choice to standard output.

—John