foreach my $nums (keys %hash){ if($hash{$nums} =~ m/^([^0]|((0\.[5-9]\d{2})|(0\.4[([^0]{2})([^0]\d)(\d[^0])])))/){ print "$nums is linked with url $hash{$nums}\n"; # or do something with $hash{$nums} } } #### (0\.4[([^0]{2})([^0]\d)(\d[^0])]) #### (0\.4[(\d[^0])([^0]\d)]) #### use strict; use warnings; my %numsh = ( '0.000' => "noughtpointnought", '0.004' => "noughtpointohohfour", '0.040' => "noughtpointohfouroh", '0.123' => "noughtpointonetwothree", '0.399' => "noughtpointthreeninenine", '0.400' => "noughtpointfourohoh", '0.405' => "noughtpointfourohfive", '0.410' => "noughtpointfouroneoh", '0.411' => "noughtpointfouroneone", '0.490' => "noughtpointfournineoh", '0.500' => "noughtpointfiveohoh", '0.904' => "noughtpointnineohfour", '1.123' => "onepointonetwothree", '4.000' => "fourpointhohoho", '4.050' => "furpintohfiveoh", '4.400' => "fourpointfourohoh", '4.405' => "fourpointfourohfive", '4.410' => "fourhtpointfouroneoh", '4.411' => "fourpointfouroneone", '4.490' => "fourpointfournineoh", '5.050' => "fivepointohfiveoh", '7.050' => "sevenpointohfiveoh", '0goodword' => 'nogoodword', ); #print scalar(%numsh).$/; foreach my $num (sort keys %numsh){ if ($num =~ m/^([^0]|(0\.([5..9]|4([^0]|(0[^0])))))/){ print "$num is $numsh{$num}".$/; } } exit(0); #### if ($num =~ m/^(0\.([0-3]|400))/){ print "$num is $numsh{$num}".$/; }