my $count = 5; my @select; my $i = 0; for (@array) { push @select, $_ if rand() < ($count / ++$i); if (@select > $count) { splice(@select, rand($#select), 1); } }