my %transactions; ... my @fields = split(/\s+/); my %rec; $rec{$_} = shift(@fields) for ( qw(date time tid status trname tramount) ); if ( $rec{status} eq "start" ) { $transactions{$rec{tid}} = \%rec; } elsif ( $rec{status} eq "stop" ) { if ( exists($transactions{$rec{tid}}) ) { # report transaction time and amount } else { warn "ERROR: stop without start: $_"; } } else { warn "ERROR: unrecognized status: $_"; }