my @set = qw(a b c); my %uniq; my @comb = grep !$uniq{$_}++, map join(",",sort split(//,$_)), glob(("{".join(",",@set)."}") x @set); print "$_\n" for @comb; __END__ a,a,a a,a,b a,a,c a,b,b a,b,c a,c,c b,b,b b,b,c b,c,c c,c,c #### my @set = qw(foo bar baz); # use glob to expand all permutations my @perm = glob( join(",", ("{".join(",",@set)."}") x @set) ); print "Permutations:\n"; print "$_\n" for @perm; # filter out duplicates my %uniq; my @comb = grep !$uniq{$_}++, map join(",",sort split(/,/,$_)), @perm; print "Combinations:\n"; print "$_\n" for @comb;