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


in reply to Two-dimensional match/regex?

I'm sure I must be missing the problem at hand to a certain extent, but have you looked at the m option for regular expression matches which allows for multi-line matches. For example, the regular expression match for the sample match given may look something like the following - \/\^\\\n.+C - to match:

  • the character sequence /^\,
  • a new-line character (\n),
  • one or more characters (.+), and,
  • the character, C.

This regular expression can be used in conjunction with the multi-line match option for regular expressions as follows, similar to how one would use the case-insensitive option for regular expressions:

if ($target =~ /\/\^\\\n.+C/m) { }

For further information see perlman:perlre

 

Update - This regular expression has been tested and does work. The effectiveness of a multi-line regular expression match can be tailored within the regular expression itself - That is, the more specific which you make your regular expression, the greater the specificity of the match, but as with all targeted solutions, there is a trade-off between sensitivity and specificity.