title: Using perl as a better grep to match multiple lines using single line mode m/RE/s
body: <p>I'm trying to grep for a text between to expressions (say <code>BEGIN</code> and <code>END</code>) that may not be on the same line with:</p>
  
  <pre><code>perl -wln -e 'm/BEGIN.+END/s and print;' &lt; file.txt
  </code></pre>
  
  <p>Note that because of the <code>s</code> modifier (in <code>m/RE/s</code>), <code>"."</code> is allowed to match newline (along with anything else).</p>
  
  <p>This lets the pattern match the words in the specific order with anything between them (i.e. pattern <code>BEGIN</code> is on one line while pattern <code>END</code> is on a few lines below).
  If the two patterns are on the same line this works fine, but not when it spans multiple line. What am I missing here?</p>