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(); } }