I think this is indeed a bug. In fact, it's very easy to see it's a bug - the /o on the first match is redundant (as there's no variable in the pattern), yet removing the /o changes the outcome.

I can confirm this bug is present in 5.12.2 as well.

Running the code with re debugging clearly shows the bug:

Compiling REx "^h(.*)" Final program: 1: BOL (2) 2: EXACT <h> (4) 4: OPEN1 (6) 6: STAR (8) 7: REG_ANY (0) 8: CLOSE1 (10) 10: END (0) anchored "h" at 0 (checking anchored) anchored(BOL) minlen 1 Guessing start of match in sv for REx "^h(.*)" against "http" Guessed: match at offset 0 Matching REx "^h(.*)" against "http" 0 <> <http> | 1:BOL(2) 0 <> <http> | 2:EXACT <h>(4) 1 <h> <ttp> | 4:OPEN1(6) 1 <h> <ttp> | 6:STAR(8) REG_ANY can match 3 times out of 214 +7483647... 4 <http> <> | 8: CLOSE1(10) 4 <http> <> | 10: END(0) Match successful! 'testing' =~ /testing/ at w line 14. Compiling REx "testing" Final program: 1: EXACT <testing> (4) 4: END (0) anchored "testing" at 0 (checking anchored isall) minlen 7 Guessing start of match in sv for REx "testing" against "testing" Found anchored substr "testing" at offset 0... Guessed: match at offset 0 1 at w line 15. Guessing start of match in sv for REx "^h(.*)" against "http" Guessed: match at offset 0 Matching REx "^h(.*)" against "http" 0 <> <http> | 1:BOL(2) 0 <> <http> | 2:EXACT <h>(4) 1 <h> <ttp> | 4:OPEN1(6) 1 <h> <ttp> | 6:STAR(8) REG_ANY can match 3 times out of 214 +7483647... 4 <http> <> | 8: CLOSE1(10) 4 <http> <> | 10: END(0) Match successful! 'testing' =~ // at w line 14. Freeing REx: "testing" Compiling REx "" Final program: 1: NOTHING (2) 2: END (0) minlen 0 Guessing start of match in sv for REx "^h(.*)" against "testing" String not equal... Match rejected by optimizer Warning: something's wrong at w line 15. Guessing start of match in sv for REx "^h(.*)" against "http" Guessed: match at offset 0 Matching REx "^h(.*)" against "http" 0 <> <http> | 1:BOL(2) 0 <> <http> | 2:EXACT <h>(4) 1 <h> <ttp> | 4:OPEN1(6) 1 <h> <ttp> | 6:STAR(8) REG_ANY can match 3 times out of 214 +7483647... 4 <http> <> | 8: CLOSE1(10) 4 <http> <> | 10: END(0) Match successful! 'testing' =~ /testing/ at w line 14. Guessing start of match in sv for REx "^h(.*)" against "testing" String not equal... Match rejected by optimizer Warning: something's wrong at w line 15. Guessing start of match in sv for REx "^h(.*)" against "http" Guessed: match at offset 0 Matching REx "^h(.*)" against "http" 0 <> <http> | 1:BOL(2) 0 <> <http> | 2:EXACT <h>(4) 1 <h> <ttp> | 4:OPEN1(6) 1 <h> <ttp> | 6:STAR(8) REG_ANY can match 3 times out of 214 +7483647... 4 <http> <> | 8: CLOSE1(10) 4 <http> <> | 10: END(0) Match successful! 'testing' =~ /testing/ at w line 14. Guessing start of match in sv for REx "^h(.*)" against "testing" String not equal... Match rejected by optimizer Warning: something's wrong at w line 15. Freeing REx: "^h(.*)" Freeing REx: ""
There's no way the last match should be /^h(.*)/.

In reply to Re: Perl bug or feature? by JavaFan
in thread Perl bug or feature? by yegg

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.