title: Perl trying to understand regex debug output
body: <p>I am trying to match some text in a loop against a regex held in a variable.</p>
  
  <p>On adding <code>use re 'debug';</code></p>
  
  <p>I see this on 1st attempt</p>
  
  <pre><code>Compiling REx "^(dev|demo|stg[12])$"
  Final program:
     1: SBOL /^/ (2)
     2: OPEN1 (4)
     4:   TRIE-EXACT[ds] (24)
          &lt;dev&gt; (24)
          &lt;demo&gt; (24)
          &lt;stg&gt; (13)
    13:     ANYOF[12] (24)
    24: CLOSE1 (26)
    26: SEOL (27)
    27: END (0)
  floating ""$ at 3..4 (checking floating) anchored(SBOL) minlen 3 
  Matching REx "^(dev|demo|stg[12])$" against "stg1"
  </code></pre>
  
  <p>and this on the 2nd attempt. The regex value in the variable hasn't changed in this loop iteration.</p>
  
  <pre><code>Compiling REx "^(dev|demo|stg[12])$"
  Matching REx "^(dev|demo|stg[12])$" against "stg1"
  </code></pre>
  
  <p>Does this mean it compiling it again the 2nd time or not? Or is it saying that it would have compiled the 2nd time but didn't and is reusing the already compiled one?</p>
  
  <p>thanks</p>
  
  <p>After posting this question, I found this one <a href="https://stackoverflow.com/questions/49227638/does-perl-cache-regex-generation">Does perl cache regex generation?</a></p>
  
  <p>So looks like, the above 2nd attempt is a cache hit (i.e. it is not recompiling it). Is my understanding correct?</p>
  
  <p>Adding the code sample as well, it is a simple match being done in a for loop</p>
  
  <pre><code>  for my $dbrow (@dbrows)
    {
      if ($dbrow-&gt;[$DB_ENV] =~ /$policy-&gt;[$PC_ENV]/
  </code></pre>
  
  <p><code>$policy-&gt;[$PC_ENV]</code> is a regex
  <code>$policy-&gt;[$PC_ENV]</code> value is not changing in this loop.
  <code>$dbrow-&gt;[$DB_ENV]</code> value is changing</p>
  
  <p>At first, I thought perl was re compiling <code>$policy-&gt;[$PC_ENV]</code> on every iteration because I saw that <code>Compiling</code> line for each iteration (not what I had expected as its value wasn't changing) but then I noticed that it only says <code>Compiling</code> but then might be finding it in its cache as it doesn't say <code>Final program:</code> etc</p>