#!/usr/bin/perl use strict; use warnings; my $max = 6; my $lines = 20; my $prob = $max / $lines; my $cnt = 0; while() { last if $cnt > $max; (rand(1) <= $prob) and $cnt++ and print; } print "last one was on line: " . $.; __DATA__ foo bar buz qiz quz foo bar buz qiz quz foo bar buz qiz quz foo bar buz qiz quz