The Perl code you're citing is completely legal under normal circumstances, and shouldn't be the source of a crash. I say "normal circumstances" because, like you said, if you do something wacky like an infinite loop or something your program can blow up at any line of code... it might not even compile. You said it uses a "huge" amount of memory, well, that's probably it. Try re-writing your code so it doesn't use so much memory (for example, iterate over each line in a file one at a time rather than trying to suck the whole file into memory at once.)
You might also check your Perl version and make sure that's up-to-date.
Gary Blackburn
Trained Killer