use strict; use warnings; my $string = 'How much wood could a woodchuck chuck if a woodchuck could chuck wood?'; my $woodCount = () = $string =~ /\bwood\b/g; print $woodCount; # prints 2