#!/usr/bin/env perl use strict; use warnings; use Algorithm::Loops qw(NestedLoops); use Text::Levenshtein::XS qw(distance); my @chars = qw(A M N U); my $depth = 5; # We're taking "five at a time" from A, M, N, U. my $min_dist = 3; # We need a minimum difference of 3 characters. my @strings; NestedLoops( [ ([@chars]) x $depth ], sub { push @strings, join('', @_) }, ); my $count = 0; foreach my $left (@strings) { foreach my $right (@strings) { if (distance($left, $right) >= $min_dist) { print ++$count, ": $left <=> $right\n"; } } } print "\n$count pairs with minimum difference of $min_dist from a set of ", scalar(@chars), " characters taken $depth at a time.\n";