title: What's the best way to clear regex matching variables?
body: <p>What's the best way to clear/reset all regex matching variables?</p>
  
  <ul>
  <li><p>Example how <code>$1</code> isn't reset between regex operations and uses the most recent match:</p>
  
  <pre><code>$_="this is the man that made the new year rumble"; 
  / (is) /; 
  / (isnt) /; 
  say $1;          # outputs "is"
  </code></pre></li>
  <li><p>Example how this may be problematic when working with loops:  </p>
  
  <pre><code>foreach (...){
     /($some_value)/;
     &amp;doSomething($1) if $1;
  }
  </code></pre></li>
  </ul>
  
  <hr>
  
  <p><em><strong>Update:</strong> I didn't think I'd need to do this, but Example-2 is only an example.  This question is about resetting matching variables, not the best way to implement them.</em>  </p>
  
  <p><em>Regardless, originally my coding style was more inline with being explicit and using if-blocks.  After coming back to this (Example2) now, it is much more concise in reading many lines of code, I'd find this syntax faster to comprehend.</em></p>