158 choose 5 = ~7.7e8 158 choose 6 = ~2.0e10 158 choose 7 = ~4.3e11 158 choose 8 = ~8.0e12 #### use Math::Combinatorics my @data = ('a', 'b', 'c', 'd', 'e', 'f', 'g'); my $nmer = 3; my $sampling_density = 2; my $combinations = Math::Combinatorics->new( count => $nmer, data => [ @data ], ); my $to_skip = 0; while (my @subset = $combinations->next_combination()) { if (0 == $to_skip) { $to_skip = int(rand($sampling_density)); Process(@subset); } else { --$to_skip; next(); } }