in reply to Regexes eating too much RAM

Perl has this nifty routine called study that might be useful to you. I don't really know though, as everytime I thought it would be useful, it wasn't.

Just thought I'd mention it anyway, in case you found it useful,