foreach $w (split) { $words++; # Increment the word count by one for each word. $char = $char + length($w); #cumulative characters for all words }