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"; }