in reply to Highlighting Regex Hits

This will surround all your hit words with square brackets and show the hit count:
use strict; use warnings; my $line = 'This line has a hit here and a hit there.'; my $word = 'hit'; my $count = $line =~ s/\b($word)\b/[$1]/gi; print "$line\n"; print "$word was found $count times\n"; __END__ This line has a [hit] here and a [hit] there. hit was found 2 times

The substitution operator returns the number of substitutions made.