#!/usr/bin/perl -w $heads=0; # initialize the number of Heads so far $N = 5000; # number of times we toss the coin for ($k = 0; $k < $N; $k++) { $toss = int(rand(2)); # 0 for Heads, 1 for Tails if ($toss == 0) {$heads = $heads + 1;} } print "\n\tIn $N tosses of a fair coin we got $heads Heads.\n\n";