in reply to Code stalls...possible memory leak?

Thanks for the responses, and special thanks to tilly for the code! So while I play with tilly's code, another sort of followup question: It seems that everyone thinks that my script is biting off more than it can chew (or chomp) so to speak. What if instead of using
$text=<INFILE>;
I used a while loop of the Text::Balanced module or tilly's code to bite off balanced brace chunks and run them through the rest of the code one at a time? This would seem to me to have the memory advantages of the
while ($line_in_file = <INFILE>)
line while more suited to my needs. Does that thinking make sense? A lot of little processes instead of one big one? This is extremely helpful advice, thanks again guys!