my $speaking = 1; my $speaker, %words; for (<>) { chomp; s/^\s+//; s/\s+$//; if ( /\-\-\-/ ) { $speaking = !$speaking; } elsif( $speaking ) { $words{ $speaker } += scalar split( /\s+/ ); } else { $_ and $speaker = $_; } }