use Tie::Hash::Sorted; my %hash = ( 5189 => 63, 3213 => 9, 2357 => 3, ); tie my %sorted_hash, 'Tie::Hash::Sorted', Hash => \%ages, Sort_Routine => sub { $a <=> $b }, ); sub next_key { my ($h,$key) = @_; foreach my $hkey (keys %$h) { return $h->{$hkey} if $hkey >= $key; } return; } print next_key(\%hash,3000) . "\n";