my %hash=(); my $highest; my @highest=grep {defined $highest ? $hash{$_}==$highest : (($highest=$hash{$_}),1) } sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash; #### my %hash=(); my %rev; my $highest=0; for (keys %hash) { $rev{$hash{$_}}{$_}++; $highest=$hash{$_} if $highest < $hash{$_}; } print sort keys %{$rev{$highest}};