That's not very efficient. You go into recursion twice,
resulting in an exponential amount of subroutine calls.
For n = 10, you call gen_seqs
1024 times. The following snippet calls gen_seqs
only n + 1 times, while dealing with n = 0
correctly:
sub gen_seqs;
sub gen_seqs {
return [] if $_ [0] <= 0;
my @s = gen_seqs $_ [0] - 1;
(map {[0 => @$_]} @s), (map {[1 => @$_]} @s)
}