Almost!
However, the last line in which "hello" is found is printed twice.
CLI:
perl -n -e "print, $count++ while /\bhello\b/g; END { print $count }" hello.out
(quotes revised for windows)
file hello.txt:
hello. hellow, world. bye
world says hello.
bye
hello, hellow, hello
not now.
done.
output
hello. hellow, world. bye
world says hello.
hello, hellow, hello
hello, hellow, hello
4
| [reply] [d/l] |
| [reply] [d/l] |
$cnt += () = m{pattern}g;
which is somewhat simpler and more natural than your reference-and-dereference trick. | [reply] [d/l] [select] |