my @hand = qw (a b c d); my @ch = @hand; for (@hand) { $k = $_; for (0..$#ch) { push (@ch, $k.$ch[$_]) unless $ch[$_] =~ /$k/; } } say "@ch\n";