my $string = 'Cathy placated her cat, which was trying to catch a caterpillar.'; my $keyword = 'cat'; my $count = 0; ++$count while $string =~ /$keyword/gi; print "Occurrences of '$keyword': $count";