use Algorithm::Combinatorics qw( permutations ); my $iter = permutations( [split //, shift // q(how do you do)] ); while (my $p = $iter->next) { print join q(), @$p, "\n"; }