in reply to Re^2: Counting the frequency of words in a string
in thread Counting the frequency of words in a string

Or
my $count = () = $text =~ /$word_regex/g;
The parens make it list context, then you take the scalar context from that.