title: Cycle through regex and replace found instance
body: <p>I currently have the following:</p>
  
  <pre><code># Pre-append "$" to variable names.
  # ['"](?:[^'"]*?(?:\\")*)*["'] Matches strings within double or single quotes.
  # (*SKIP)(*F) Causes the preceding pattern to fail. Tries to match the pattern on the right side of the | operator using the remaining strings.
  
  my $temp = $entire_line;    
  while ($temp =~ /['"](?:[^'"]*?(?:\\")*)*["'](*SKIP)(*F)|([A-Za-z0-9_]+)/g){
      my $variable_name = $1;     
      $entire_line =~ s/$variable_name/\$$variable_name/;     
  }
  </code></pre>
  
  <p>Given <code>$entire_line = ((factor0 + factor1) * factor2) + factor0</code></p>
  
  <p>I would like my output to be:</p>
  
  <p><code>(($factor0 + $factor1) * $factor2) + $factor0</code></p>
  
  <p>However, I'm getting:</p>
  
  <p><code>(($$factor0 + $factor1) * $factor2) + factor0</code></p>
  
  <p>I know this is happening because it is finding the first instance of<code>factor0</code> twice. Is there a good way to prevent this from happening and replace the instance that is being found?</p>
  
  <p>Also do I need to use the <code>$temp</code> variable?</p>
  
  <p>Thanks for your help. </p>