my %hash=(); my $highest; my @highest=grep {defined $highest ? $hash{$_}==$highest : (($highest=$hash{$_}),1) } sort { $hash{$b} <=> $hash{$a} || $a cmp $b } keys %hash;