title: Perl one liner to increment a value and replace text
body: <p>I have a line in some files where only the year differs -- I need to increment the year and replace the preceding text, for example:</p>
  
  <pre><code>tdef 12 linear 18Z31dec2012 1mo
  </code></pre>
  
  <p>should become:</p>
  
  <pre><code>tdef 12 linear 00Z01jan2013 1mo
  </code></pre>
  
  <p>I have a perl one liner that I can't get to replace the text and increment at the same time. I've tried quite a few combinations, the correct formatting evades me. This increments but of course I lose the text:</p>
  
  <pre><code>perl -pe 's/18Z31dec(\d+)/ 1 + $1 /ge'
  </code></pre>
  
  <p>I can't figure how to insert any text on the substitution and retain the incremented year:</p>
  
  <pre><code>perl -pe "s/18Z31dec(\d+)/'00Z01jan($1 + 1)'/ge"
  </code></pre>
  
  <p>Outputs this:</p>
  
  <pre><code>tdef 12 linear 00Z01jan( + 1) 1mo
  </code></pre>