in reply to Fast lookup for prefixes in hash

Here's a somewhat different way (no regex involved):

my $number="31456000001"; my $len = (grep {exists $hash{substr($number,0,$_)}} 2..5)[-1]; my $result = $hash{substr($number,0,$len)};
This finds the longest matching key in four iterations, then obtains the corresponding hash value. The exists function is used to avoid autovivifying false keys in %hash.

After Compline,
Zaxo