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.
In reply to Re: Highlighting Regex Hits
by toolic
in thread Highlighting Regex Hits
by rlrandallx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |