my $select = 1000; my @ssns; while (my($ssn) = $sth->fetchrow_array()) { push @ssns, $_ if rand() < ($select / ++$count); if (@ssns > $select) { splice(@ssns, rand($#ssns), 1); } }