my ($min, $max) = (1e10, -1e10); for my $value (keys %hash) { $min = $value if $value < $min; $max = $value if $value > $max; } # $now $min has the smallest key and $max the highest one