for my $key (keys %coll_key_hash){ for my $rec (@recs_read){ my @fields = split(/\|/, $rec); if($fields[0] eq '010'){ $print_record = 0; if($fields[3] =~ $key){ #shouldn't this be /$key/ ? $print_record = 1; unless($key eq $prev_key){ $prev_key = $key; print_record ("CUST-BEG|$seq\n",' '); } } } if($print_record){ print_record ("$rec\n",'c'); } } }