jrw has asked for the wisdom of the Perl Monks concerning the following question:

Seeking wisdom for a regexp like s/(^...$\n)+//m which seeks to delete all three-character interior lines. My actual regexp is different, but it has the sequence $\n in it, which perl interprets as $\ n rather than $ \n. I can trick it by adding /x and then interposing a space between $ and \n, but I'd rather not. I wish there were a \z variation that meant "match an interior newline" when used with /m.

Replies are listed 'Best First'.
Re: Using /m when $ is followed by punctuation
by ikegami (Patriarch) on Aug 05, 2014 at 22:40 UTC
      Thanks, I see that now. Do you know of an answer to the general question: how to get perl to parse $ followed by by an escape sequence as $ \whatever rather than $\ whatever?

        I don't think you'd ever need to do that, but I can think of a couple of solutions:

        • (?x: $ )
        • (?=\n|\z) (if /m is in effect)
        • (?=\n?\z) (if /m isn't in effect)
        • (?![^\n]) (if /m isn't in effect)