The regex will first get $1 and any other variables interpolated, so you don't need to store it someplace else, or do anything special to it to get Perl to recognize it.

However, the code is slightly flawed. YAPE::Regex::Explain will tell you that /(a|b)+/ does not match as /a+|b+/, but rather, it matches like /[ab]+/, and stores the LAST character matched into $1. This is because the regex code looks like:
1. OPEN 1 2. MATCH 'a' OR 'b' 3. CLOSE 1 4. TRY GOTO 1
So it can match lines like "#=#=#=#=#". Icky, no? Sadly, to get the regex to work like you'd expect, you have to do something like:
sub zapwrap { my ($this, $next) = @_; return $this =~ m{ ^ \# # '#' at the beginning of the string ( [\#=] ) # a '#' or an '=' (saved to $1) \1* # that character 0 or more times $ # end of line }x and $next =~ m{ ^ # beginning of string $1+ # that character 1 or more times $ # end of string }x; }


japhy -- Perl and Regex Hacker

In reply to Re: Regexp syntax nuance question, storing $1 (code) by japhy
in thread Regexp syntax nuance question, storing $1 (code) by deprecated

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.