A couple of ideas off the cuff:
-
Set $/ and let perl handle reading records and then parse out what you need a whole recrod at a time
-
When you see the start of a record, use tell() to save off the location. Read enough to determine if the record's interesting, and seek() back to the start if it is
-
If the data you're looking at is relatively static, you could preprocess things and use a tied hash to store record number => tell() offeset; when you process it you just seek directly to the start of the record
Of course then again, unless you're talking about really, really, really large amounts of information in each record you're probalby going to introduce more complexity than its worth trying to minimize memory usage than if you just kept state as you go along.