note
salva
Generating all the combination and then filtering out those that don't have the right number of ones can be pretty inefficient, specially when the number of zeros is big and the number of ones small.
<p>In any case, you can also use a regular expression for generating all the binary numbers of some given length :-)
<c>
my $length = 5;
my $str = "0" x $length;
my $start = $str . "1";
do {
print "$str\n";
} while ($str =~ s/^(1*0)/substr $start, -length $1/e)
</c>
11121888
11121893