Can an iterative replacement procedure be specified with a single s///?
<p>Suppose we want to replace with <code>000</code> each instance of <code>1</code> that appears before the <em>first</em> character that is neither <code>0</code> nor <code>1</code>.</p>

<p>For example, if the original string is</p>

<pre><code>"0011101TUVW0123ABC0123"
</code></pre>

<p>then the desired replacement would yield the string</p>

<pre><code>"000000000000000TUVW0123ABC0123"
</code></pre>

<p>In Perl 5, assuming that <code>$_</code> holds the input string, then something like this will do the trick:</p>

<p><code>'*any* constant you like!' while s/^(0*)1/${1}000/;</code></p>

<p>This method just keeps applying the same substitution rule (<code>s/^(0*)1/${1}000/</code>) until it "converges" (i.e. ceases to change the input).</p>

<p>I want to know if there's a <code>s///</code> substition such that a <em>single</em> application of it achieves the same result.  (Think of the way that a <em>single</em> application of <code>s/1/000/g</code> is capable of replacing <em>every</em> occurrence of <code>1</code> with <code>000</code>.)</p>

<hr>

<p>Note that a <em>single</em> application of <code>s/^(0*)1/${1}000/g</code>, the <code>/g</code> notwithstanding, will replace only the first occurrence of <code>1</code>, resulting in:</p>

<pre><code>"000001101TUVW0123ABC0123"
</code></pre>