The other answers look good if formulae is
guaranteed to exist on at most 1 line at a time. If it can appear twice on the same line, this will work.
use strict;
my $i;
while (<DATA>) {
my @m = ($_ =~ /formulae/g);
$i += @m;
}
print "Found $i matches\n";
__DATA__
message one
message two formulae formulae
message threee