title: How can I preserve whitespace when I match and replace several words in Perl?
body: <p>Let's say I have some original text: </p>
  
  <pre>
  here is some text that has a substring that I'm interested in embedded in it.
  </pre>
  
  <p>I need the text to match a part of it, say: "<code>has a substring</code>".</p>
  
  <p>However, the original text and the matching string may have whitespace differences.  For example the match text might be:</p>
  
  <pre>
  has a
  substring
  </pre>
  
  <p>or</p>
  
  <pre>
  has  a substring
  </pre>
  
  <p>and/or the original text might be:</p>
  
  <pre>
  here is some
  text that has
  a substring that I'm interested in embedded in it.
  </pre>
  
  <p>What I need my program to output is:</p>
  
  <pre>
  here is some text that [match starts here]has a substring[match ends here] that I'm interested in embedded in it.
  </pre>
  
  <p>I also need to preserve the whitespace pattern in the original and just add the start and end markers to it.</p>
  
  <p>Any ideas about a way of using Perl regexes to get this to happen? I tried, but ended up getting horribly confused.</p>