Text::Fuzzy has a maximum distance setting. set_max_distance of Text::Fuzzy.
It seems not to have a function that will return matched strings with their distances, but you could iterate over the data yourself using the distance method. See code below for an example.
I think the nearest method in list context will return the list of strings with the shortest distance, so will not be all those within the maximum distance. Both those would be useful to have - maybe submit a feature request?
# 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
|