my @superset = split /\s+/, 'convert python to perl'; my $N = $#superset; # one less element than in the previous example for my $combo (0..((2**$N) - 1)) { # a combo is a bit mask for my $selector (0..$N) { # a selector is also a bit position print $superset[$selector]; if ($selector == $N) { print "\n"; next; } if ((2**$selector) & $combo) { print ' '; } else { print '-'; } } }