To elaborate a bit what should probably be happening is that the regex engine should always backtrack on .* into the equivalent of NOTHING, but instead it commits to the match and fails under /m once it reaches \n.
perl5.9.5 -Mre=debug -e 'my @re = (qr/.*\z/, qr/.?\z/, qr/(|.+)\z/); "\n" ~~ $_ for @re'

Compiling REx ".*\z"
Final program:
   1: STAR (3)
   2:   REG_ANY (0)
   3: EOS (4)
   4: END (0)
floating ""$ at 0..2147483647 (checking floating) anchored(MBOL) implicit minlen 0 
Compiling REx ".?\z"
Final program:
   1: CURLY {0,1} (4)
   3:   REG_ANY (0)
   4: EOS (5)
   5: END (0)
floating ""$ at 0..1 (checking floating) minlen 0 
Compiling REx "(|.+)\z"
Final program:
   1: OPEN1 (3)
   3:   BRANCH (5)
   4:     NOTHING (8)
   5:   BRANCH (FAIL)
   6:     PLUS (8)
   7:       REG_ANY (0)
   8: CLOSE1 (10)
  10: EOS (11)
  11: END (0)
floating ""$ at 0..2147483647 (checking floating) minlen 0 
Guessing start of match in sv for REx ".*\z" against "%n"
Found floating substr ""$ at offset 0...
Position at offset 0 does not contradict /^/m...
Guessed: match at offset 0
Matching REx ".*\z" against "%n"
   0 <> <%n>                 |  1:STAR(3)
                                  REG_ANY can match 0 times out of 2147483647...
   0 <> <%n>                 |  3:  EOS(4)
                                    failed...
                                  failed...
Match failed
Guessing start of match in sv for REx ".?\z" against "%n"
Found floating substr ""$ at offset 0...
Guessed: match at offset 0
Matching REx ".?\z" against "%n"
   0 <> <%n>                 |  1:CURLY {0,1}(4)
                                  REG_ANY can match 0 times out of 1...
   0 <> <%n>                 |  4:  EOS(5)
                                    failed...
                                  failed...
   1 <%n> <>                 |  1:CURLY {0,1}(4)
                                  REG_ANY can match 0 times out of 1...
   1 <%n> <>                 |  4:  EOS(5)
   1 <%n> <>                 |  5:  END(0)
Match successful!
Guessing start of match in sv for REx "(|.+)\z" against "%n"
Found floating substr ""$ at offset 0...
Guessed: match at offset 0
Matching REx "(|.+)\z" against "%n"
   0 <> <%n>                 |  1:OPEN1(3)
   0 <> <%n>                 |  3:BRANCH(5)
   0 <> <%n>                 |  4:  NOTHING(8)
   0 <> <%n>                 |  8:  CLOSE1(10)
   0 <> <%n>                 | 10:  EOS(11)
                                    failed...
   0 <> <%n>                 |  5:BRANCH(8)
   0 <> <%n>                 |  6:PLUS(8)
                                  REG_ANY can match 0 times out of 2147483647...
                                  failed...
   1 <%n> <>                 |  1:OPEN1(3)
   1 <%n> <>                 |  3:BRANCH(5)
   1 <%n> <>                 |  4:  NOTHING(8)
   1 <%n> <>                 |  8:  CLOSE1(10)
   1 <%n> <>                 | 10:  EOS(11)
   1 <%n> <>                 | 11:  END(0)
Match successful!
Freeing REx: ".*\z"
Freeing REx: ".?\z"
Freeing REx: "(|.+)\z"

In reply to Re: Strange regex to test for newlines: /.*\z/ by avar
in thread Strange regex to test for newlines: /.*\z/ by betterworld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.