in reply to Out of memory

mmh sounds very strange with few hundrends Mb. Anyway you can use multiline regex with the m modifier
against a pair of lines at time:1-2,2-3,3-4.. at least to debug why you go out of memory. As you said you are not principally a Perl programmer: are you using strict and warnings? In fact i humbly but strongly suspect the problem is not the size, of the file.

L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.