sub perms { return !@_ ? [] : map{ my $next = $_; map{ [ $_[ $next ], @$_ ] } perms( @_[ 0 .. $_-1, $_+1 .. $#_ ] ); } 0 .. $#_; } print @$_ for perms qw[ a b c ];; a b c a c b b a c b c a c a b c b a