my $count=0; while ( (my $r = int(rand(6)) +1 ) != 6) { #int(rand(6) generates nums 0-5 $count++; } print "took ++$count tries to get a 6\n";