my @set = qw|0 1 2 3|; foreach my $index (0..2**@set-1) { my @subset; foreach my $pos (0..@set-1) { push @subset, $set[$pos] if ($index >> $pos) % 2; } print join " ", @subset, "\n"; }