in reply to negative look behind (again)

Why? Because negative lookbehind is satisfied at any position except immediately after the given subpattern. Thus your (.*?) is free to match at the very beginning. Using a lookahead may accomplish what you had in mind (if $1 must contain the start tag).

if (/^(?!TAGS)(.*?)TAG2/x ) { ...

Replies are listed 'Best First'.
Re^2: negative look behind (again)
by AnomalousMonk (Archbishop) on Jan 20, 2014 at 18:52 UTC
    [From the OP:]
    if (/^(?<!TAGS)(.*?)(?=TAG2).*$/x ) {
        print $1, "\n";
    }

    Looked at another way,  ^(?<!TAGS) asserts that one wants a string that does not have certain characters before the start of the string. In the absence of the  /m regex modifier, this assertion can never fail!

    With  /m active (allowing  ^ to also match after an embedded newline sequence), an assertion of this sort might be written that could actually fail, but then it would be an assertion about the end of the preceding line, and not about the start of the current line.