in reply to Perl Multiline Regex
Categorically speaking, one of the most-important techniques in all of data processing is the notion of working with known-sorted files, in what is called “unit record processing.” It is literally how data processing was done before computers were invented.
All you need to do is to remember what the (one...) previously-read record was. You can do a tremendous number of things, extremely quickly, just by comparing this record to the previous one.