use strict; use warnings; my $text = "match other match not useful match sample word"; my $string = "match"; my @matches = $text =~ m/$string/g; my $count = @matches; print $count;