title: Perl Regex substituting all instances of a character with different values in different iterations
body: <p>I have a simple question related to Regex in Perl.
  Let's say I have a string <code>abcb</code> and I am iterating through a loop. All I want is both of the <code>b</code> characters in <code>abcb</code> to be substituted by the value of iterator in each loop. When I use the <code>$string=~s/b/$iterator/g</code>, it replaces all <code>b</code> by the first value of iterator.    </p>
  
  <p>Code:</p>
  
  <pre><code>#!/usr/bin/perl 
  
  use strict;
  use warnings;
  
  my $string="abcb";
  for (my $iterator=0;$iterator&lt;3;$iterator++)
  {
      $string=~s/b/$iterator/g;
      print $string;
      print " ";          
  }
  </code></pre>
  
  <p>Output Obtained: <code>a0c0 a0c0 a0c0</code></p>
  
  <p>Desired Output: <code>a0c0 a1c1 a2c2</code></p>