use warnings; use strict; my $g = 100; my %c; my %n; while(<>) { my $l = /(.)/ && lc($1); my $c = \@{$c{$l}}; if (rand() < $g / ++$n{$l}) { splice @$c, int(rand(@$c)), $g <= @$c, $_; } } print @$_ for values(%c);