use strict; use warnings; use feature 'say'; use Algorithm::Combinatorics qw(permutations); my $zeros = 7; my $ones = 3; # if you want the iterator force scalar context, as in: # my $iter = permutations(\@data); say join('',@$_) for permutations( [ (0) x $zeros, (1) x $ones] );