title: Add number of white spaces at begin of each line (within one string)
body: <p>This is kind of a follow-up question to <a href="https://stackoverflow.com/questions/6847443/perl-add-character-to-begin-of-a-line">Perl: add character to begin of a line</a>.</p>
  
  <p><strong>The Situation</strong><br>
  Within an existing Perl script I've got a reasonable long string <code>$str</code> containing an unknown number of line breaks (<code>\n</code>). There is now line break at the end of the string.</p>
  
  <pre><code>$str = "Hello\nWorld.\nHow is it going?"
  </code></pre>
  
  <p><strong>The Problem</strong><br>
  I would like to add a certain (constant) number of white spaces at the beginning of each line within the string: (in this case 3)</p>
  
  <pre><code>$str = "   Hello\n   World.\n   How is it going?"
  </code></pre>
  
  <p><strong>First approach</strong>
  My first approach was the following RegEx</p>
  
  <pre><code>$str =~ s/(.*?\n)/   \1/g;
  </code></pre>
  
  <p>And to cache the last line, which is not terminated by a new line</p>
  
  <pre><code>$str =~ s/(.*)\n(.*)?$/\1\n   \2/g;
  </code></pre>
  
  <p><strong>The Wish</strong><br>
  First. The above lines work perfectly and do exactly what I intended. But. I know, RegEx are powerful and thus I'm pretty sure, one can do the same thing in just one short RegEx. Unfortunately, I was yet not able to achieve this. (It's very likely, that I'm thinking way too complex.)</p>
  
  <p>So, what possibilities do one have for this problem?<br>
  Thank you for any answer.</p>