: $line = 'This line has a hit here and a hit there."; $word = 'hit'; $count = 0; while ($line =~ /\b$word\b/gi )#I also tried "/gic" & pos() { $line = "$`".'['."$&".']'."$'"; $count++ } print "$lino $line\n"; : print "$word was found $count times\n";