Here are some benchmarks: (fixed from TLM's)
use strict; use warnings; use Benchmark 'cmpthese'; my $sz = ( shift || 10 ) - 4; my $X = 'N' . 'x' x $sz . '000'; my $Y = 'N' . 'x' x $sz . '001'; print("X = $X\n"); print("Y = $Y\n"); print("\n"); cmpthese( -1, { '/^N(?!.*00$).*$/ failure' => sub { scalar $X =~ /^N(?!.*00$).*$/ }, '/^N(?!.*00$).*$/ success' => sub { scalar $Y =~ /^N(?!.*00$).*$/ }, '/^N(?!.*00$)/ failure' => sub { scalar $X =~ /^N(?!.*00$)/ }, '/^N(?!.*00$)/ success' => sub { scalar $Y =~ /^N(?!.*00$)/ }, '/^N.*(?<!00$)$/ failure' => sub { scalar $X =~ /^N.*(?<!00$)$/ }, '/^N.*(?<!00$)$/ success' => sub { scalar $Y =~ /^N.*(?<!00$)$/ }, '/^N.*(?!00)..$/ failure' => sub { scalar $X =~ /^N.*(?!00)..$/ }, '/^N.*(?!00)..$/ success' => sub { scalar $Y =~ /^N.*(?!00)..$/ }, });

Results:

X = Nxxxxxx000 Y = Nxxxxxx001 /^N.*(?!00)..$/ failure 278229/s -- /^N.*(?<!00$)$/ failure 330512/s 19% /^N(?!.*00$).*$/ success 536004/s 93% /^N.*(?!00)..$/ success 540980/s 94% /^N(?!.*00$)/ success 633900/s 128% /^N(?!.*00$)/ failure 743994/s 167% /^N(?!.*00$).*$/ failure 750772/s 170% /^N.*(?<!00$)$/ success 789866/s 184%

Combined success and failure results:
(If the numbers are evenly distributed, the chance of failure is 0.01.)

/^N(?!.*00$).*$/ 750772/s * 0.01 + 536004/s * 0.99 = 538151.68/s -- /^N.*(?!00)..$/ 278229/s * 0.01 + 540980/s * 0.99 = 538352.49/s 0% /^N(?!.*00$)/ 743994/s * 0.01 + 633900/s * 0.99 = 635000.94/s 18% /^N.*(?<!00$)$/ 330512/s * 0.01 + 789866/s * 0.99 = 785272.46/s 46%

/^N.*(?<!00$)$/ is the winner as expected, and it won by no small margin (24%).


In reply to Re^2: ^N.*(?!00$) by ikegami
in thread ^N.*(?!00$) by ady

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.