http://www.perlmonks.org?node_id=1200744


in reply to Regex Optional capture doesn't

I think .+ is greedy and eats the rest of the string.

But the regex is forced to backtrack if <(\w+TagIwant\b) is not optional otherwise it concludes happily.

Changing to .+? should solve this.

UPDATE

just tested, not my day. declaring myself officially (mentally) ill.

UPDATE

an elegant solution is buried at the end of this discussion here

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!