use Math::Combinatorics; my @n = qw(0 1 2 3 4 5 6 7 8 9); my $combinat = Math::Combinatorics->new(count => 2, data => [@n], ); $i = 0; while(my @permu = $combinat->next_permutation){ print join('', @permu)."\n" if ($i >= 999999 && $i <= 1000001); $i++; print "on $i\n" if ($i % 100000 == 0); last if ($i > 1000001); }