It isn't $&, it is an invisible "what pattern did the last successful match use?" saved for just this purpose.

I think the easiest way to clear it out (if I guess correctly what you mean by that) is to find a pattern that acts like the empty pattern would were it not special-cased. The simplest one I know is the empty lookahead:

"" =~ /(?=)/;

That'll always match, and do so pretty quickly; once matched, it'll be remembered as the last successful match, so an empty pattern will use it and always match.

But be warned that this is an ugly workaround that'll make your code harder to write in the first place, and harder to maintain in the future. Better by far would be to avoid the problem in the first place.

Since the original check, $signer =~ m/\Q$exp_sender\E/, is identical to:

index($signer, $exp_sender) > 0
except for the special-case behaviour on the empty pattern, I suspect the latter is what you actually want.

Hugo

In reply to Re: Re: Re: Regular Expression gotchas ? by hv
in thread Regular Expression gotchas ? by the_Don

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.