in reply to when a script runs out of memory

Take a look at the $^M variable in perlvar. I have never used it and there seem to be various caveats, but it might work for you. If you're really running out of memory, you usually have bigger problems. :-)