#!/usr/bin/perl use warnings; use strict; use List::Util 'shuffle'; my $a = "KAMEL"; my @b = split("", $a); my %c; my $x = 0; my $n = 0; while ($x < 1000) { @b = shuffle(@b); my $s = join("", @b); if (exists($c{$s})) { $x++; } else { $c{$s} = ""; $x = 0; $n++; } } my @e = sort(keys(%c)); foreach my $i (@e) { print "$i\n"; } print "$n permutations, probably all.\n";