# code not tested my $max_distance = 4; my $some_label = 'blortbertblart'; my %targets_hash = (...); my $distance_finder = Text::Fuzzy->new( $some_label, trans => 1); $distance_finder->set_max_distance ($max_distance); my %poss_matches; foreach my $target (keys %targets_hash) { my $distance = $distance_finder->distance( $target_label ); next if !defined $distance; $poss_matches{$distance} //= []; push @{$poss_matches{$distance}}, $target; } # do stuff with @poss_matches