What is the best way to search for the line number for a substring in perl string? For e.x.:
Searching for “escape” in
"How to Format
► put returns between paragraphs
► for linebreak add 2 spaces at end
► _italic_ or **bold**
► indent code by 4 spaces
► backtick escapes `like _so_`
► quote by placing > at start of line
► to make links
<http://foo.com>
[foo](http://foo.com)"
should give 6 as the line number.
Thought of another solution. In sufficiently recent Perls, you can open a filehandle onto a string, and then just use the special
$.variable to automatically keep track of the line number: