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