http://www.perlmonks.org?node_id=71792


in reply to Sentence Measurer

Something like split " ", $sentence should be sufficent for counting words in a scalar. .

Try using this:
my %sentence_count; my @sentences = ( "Hello, how are you doing today?", "Where is the bathroom, pablo?", "My feet have the most beautiful odour!", "It's five o'clock" ); foreach (@sentences) { $sentence_count{scalar(split " ",$_)}++; } foreach (keys %sentence_count) { print "$sentence_count{$_} sentences have $_ words\n"; }