#!/usr/bin/perl use strict; use warnings; my @hand = qw (a b c d); my @ch; for my $k (@hand) { push(@ch,$k); for my $lst (@ch) { push (@ch, $k.$lst) if index($lst,$k)==-1; } } print join("\n",@ch)."\n";