in reply to Reducing memory usage while matching log entries

An easy way is to sort the file on disk using the lock id as the primary sorting key with some CPAN module as Sort::External, Sort::Key::Merger or even the sort command.

After that, assuming nested locks are not allowed, every lock entry should be followed by an unlock one, something very easy to parse!