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

$
yeah that very character so confusing when working upon regex with /m i.e. multi line modifier
how can we differentiate it with scalar variable when it's right off side by side Please give us so clear but brief complete tutorial
  • Comment on Confusion in working upon regex with /m

Replies are listed 'Best First'.
Re: Confusion in working upon regex with /m
by ikegami (Patriarch) on Nov 12, 2021 at 05:07 UTC

    If I understand correctly, you want to do something like this:

    /^abc$\ndef$/

    But you are faced with $\ getting treated as a variable name. You could use one of the following instead:

    /^abc(?:$)\ndef$/m
    /^abc$(?:\n)def$/m
    / ^ abc $ \n def $ /xm
    But the following ones are better:
    /^abc\ndef$/m
    / ^ abc \n def $ /xm
Re: Confusion in working upon regex with /m
by LanX (Saint) on Nov 12, 2021 at 00:57 UTC
Re: Confusion in working upon regex with /m
by Fletch (Bishop) on Nov 12, 2021 at 03:54 UTC

    If you use /x you can separate whatever "variable looking" bits follow (or proceed, for that matter) with whitespace.

    qr/blah \s+ blah $ yackety \s+ schmakety/mx

    Edit: Derp; bad example is bad; see below for better.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      That will never match. $ has to be followed by a line feed or EOS, and you also require that it's followed by a y. Those are mutually exclusive requirements.