-w; use strict; my @flip = ('H','T'); my @results; my @heads; for (1..200) { push(@results,$flip[rand(2)]); } my $head_count; foreach (@results) { if ($_ =~/H/) { print $_; $head_count++; } else { print " "; push(@heads,$head_count) if ($head_count != 0); $head_count= 0; } } $head_count = 0; print "\n\n"; foreach (@heads) { $head_count += $_; } print "The tally of heads (in a row) looks like:\n"; print join('|',@heads); print "\n"; print "The number of heads total is:\n"; print $head_count; #### HHHHH H HH H H H H H H H H HH H HH H H H HHHH H H H HHHHHH HH HHHHH H HHH HHHHHH H HHH H HH HH H H H HHHH HH HH H H HH H H HH HHH H HH H The tally of heads (in a row) looks like: 5|1|2|1|1|1|1|1|1|1|1|2|1|2|1|1|1|4|1|1|1|6|2|5|1|3|6|1|3|1|2|2|1|1|1|4|2|2|1|1|2|1|1|2|3|1|2 The number of heads total is: 88