title: How to make a perl one-liner "line-endings agnostic"
body: <p>I have scratched my head for one hour on a perl oneliner failing because the file had CRLF line endings. It has a regex with group match at the end of the line, and the CR got included in the match, making bad stuff with using the backreference for replace.</p>
  
  <p>I ended up specifying the CRLF manually in the regex, but is there a way to get perl handle automatically line-ending <em>whatever they are</em>?</p>
  
  <p>Original command is </p>
  
  <pre><code>perl -pe  's/foo bar(.*)$/foo $1 bar/g' file.txt
  </code></pre>
  
  <p>"Correct" command is</p>
  
  <pre><code>perl -pe  's/foo bar(.*)\r\n/foo $1 bar\r\n/g' file.txt
  </code></pre>
  
  <p>I know I can also convert line endings before processing, I'm interested in how to get Perl handle this case gracefully.</p>
  
  <p>Example file (save with CRLF line endings!)</p>
  
  <pre><code>[19:06:57.033] foo barmy
  [19:06:57.033] foo baryour
  </code></pre>
  
  <p>Expected output</p>
  
  <pre><code>[19:06:57.033] foo my bar
  [19:06:57.033] foo your bar
  </code></pre>
  
  <p>Output with original command (bar goes at line beginning because it's matched together with carriage return):</p>
  
  <pre><code>bar:06:57.033] foo my
  bar:06:57.033] foo your
  </code></pre>