in reply to Efficiently parsing a large file

How about using a bitmap state hash, deleting as you go to limit memory footprint. Single pass.....

my %states = ( 'begin' => 1, 'doing-work' => 2, 'complete' => 4, ); my $re = join '|', keys %states; $re = qr/^(\S+)\s*($re)/; my %fail_decode = ( 6 => 'no begin', 5 => 'no doing work', 4 => 'no begin or doing work', 3 => 'no complete', 2 => 'no begin or complete', 1 => 'no doing work or complete', ); my %status; while(<DATA>) { next unless /$re/; $status{$1} += $states{$2}; delete $status{$1} if $status{$1} == 7; } printf "$_\t%s\n", $fail_decode{$status{$_}} for keys %status; __DATA__ foo begin bar begin baz complete foo doing-work foo complete bar doing-work

cheers

tachyon