my %needed_transaction; while (my %record = get_record()) { if ($record{CALL_INIT} and $record{CHAN_TYPE} =~ /TCH/ ) { $needed_transaction{ $record{TRAN_ID} } = 1; } elsif ($record{CALL_RESPONSE} and $needed_transaction{ $record{TRAN_ID} } ) { output_record(%record); delete $needed_transaction{ $record{TRAN_ID} }; } }