use Algorithm::FastPermute; sub combinations { return [] unless @_; my $first = shift; my @rest = combinations(@_); return @rest, map { [$first, @$_] } @rest; } for(combinations('a'..'c')){ my @c = @{$_}; permute {print @c , "\n"} @c; } __END__ c b bc cb a ac ca ab ba abc acb cab bac bca cba