my $t = 0; # nr of lines already considered my $N = 10; # nr of lines in file do{ my $line = <>; }until(($N-$t++)*rand < 1); print $line;