I hacked some batch files that I must now support. I needed a way to set return codes for when the batch files exit, but there's not an easy way to do it in NT 4.0 or earlier (Win2k allows an exit code with the exit command).
So, I used perl. Before exiting the batch file, I called
perl -e "exit x"
where x is the exit code I want to set. This sets the corresponding ERRORLEVEL in dos.