my ($h_run, $t_run, $longest_run) = (0,0,0); while () { if (int rand 2) { # had silly use of flip-flop -- thanks, tlm ++$h_run; $longest_run = $h_run if $h_run > $longest_run; $t_run = 0; } else { #similarly } }