my $c = 0; for (my $i=0;$i<3**7;$i++) { my @p = ([],[],[]); my $k = $i; for (my $j=0;$j<7;$j++) { push @{$p[$k%3]},$j; do { use integer; $k /= 3}; } next unless @{$p[0]} && @{$p[1]} && @{$p[2]}; next unless ($p[0][0]<$p[1][0]) && ($p[1][0]<$p[2][0]); print "[@{$p[0]}][@{$p[1]}][@{$p[2]}]\n"; $c++; } print "$c total\n";