in reply to How to match and transform a multiline pattern?

In your regex you could specify \n to indicate a newline. (Play with this; your file might contain \r or a control-character as a line separator.)

So, for example, you could have  if /.+FIRST.+\n.+SECOND.+\n.+THIRD.+\n.+FOURTH/

which would only match a string spanning four lines, the first containing FIRST, the second containing SECOND, etc.
This is my first attempt at helping out, so I apologize in advance. 8-)

Replies are listed 'Best First'.
Re^2: How to match and transform a multiline pattern?
by nbhatia (Novice) on Apr 20, 2007 at 17:58 UTC
    I think I know what you are saying, but my mental block is with how to get the four lines in the first place. Since these lines are being read one at a time from a file, how would I know when to read more than one? Are you suggesting that I read the whole file in to a single string and do substitutions on the whole thing?
      Two thousand lines of text is not a great deal.
      If you did treat it all as a single string, you could do a single $a =~ s/p/r/g;, changing all occurrences of the pattern p to r in buffer a.
        Agreed - 2000 lines is not large at all. I just sucked in the whole file and was able to convert it successfully using $a =~ s/p/r/g;.
        Thanks so much.