my ($maxcount) = sort { $idcount{$b} <=> $idcount{$a} } keys %idcount; my $highest = join(",CO", grep { $idcount{$_} == $maxcount } keys %idcount );