for (my $i=0; $i<@parsed_file; $i++) { my @record = $parsed_file[$i]; my $record = join ('', @record); @record = split (/\t/, $record); $num = $freq{$record[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_; my @id; push (@id, $record[0]); } # i sort based on id to extract unique id's my @sorted_array = sort {$freq{$b}{"freq"} <=> $freq{$a}{"freq"}} keys %freq; ##print "$sorted_array[0]\n"; for (my $i=0; $i<@parsed_file; $i++) { my @hit = $parsed_file[$i]; my $hit = join ('', @record); @hit = split (/\t/, $record); my $c=0; my $id2 = $hit[0]; foreach my $id (@sorted_array) { if ($id == $id2) { ++$c; } # try to match unique id's to the file and print the first instance found, but it prints everything if ($c == 1) { print "$parsed_file[$i]\n"; } } }