in reply to is this the most efficient way to double-parse a large file?

If your file is huge, then it is probably more of a database job. Otherwise, you could build an index for ALL clients in the first round using tell and then use seek to retrieve those lines in the second round. Whether this extra complexity is justified, would depend on the size of your log file and the number of clients you have.

Update: sample code

use strict; use warnings; my $tell = tell DATA; while(<DATA>){ if( /^(.*?):/ ) { my $client = $1; push @{$lines{$client}}, $tell; $triggered{$client}++ if /trigger/; } $tell = tell DATA; } print "Found triggers for ", join( ", ", keys %triggered ), ".\n"; for( keys %triggered ) { print "Log for client $_:\n"; for( @{$lines{$_}} ) { seek DATA, $_, 0; my $line = <DATA>; print "\t$line"; } } __DATA__ arthur: line 1 arthur: line 2 trigger ford: line 3 # some comment zaphod: line 4 zaphod: line 5 trigger arthur: line 6 ford: line 7