title: Perl multiline replace at multiple places in a file
body: <p>I have a file <code>temp.txt</code> with the following contents:</p>
  
  <pre class="lang-none prettyprint-override"><code>CREATE  TABLESPACE TSASNCA
   IN NODEGROUP IBMCATGROUP
   PAGESIZE 8192
   MANAGED BY DATABASE
   USING
  (
   FILE 'TSASNCA' 482M
  )
   EXTENTSIZE 8
   BUFFERPOOL DPROPR8KBP;
  
  CREATE  TABLESPACE TSASNUOW
   IN NODEGROUP IBMCATGROUP
   PAGESIZE 8192
   MANAGED BY DATABASE
   USING
  (
   FILE 'TSASNUOW' 10M
  )
   EXTENTSIZE 8
   BUFFERPOOL DPROPR8KBP;
  </code></pre>
  
  <p>In the above file I would like to replace the two or n occurrences of text starting from "MANAGED BY DATABASE" and ending with ")" with <code>MANAGED BY AUTOMATIC STORAGE</code>.</p>
  
  <p>I tried the following and it seems to be greedy and matching everything from the first occurrence of <code>MANAGED BY DATABASE</code> to the last occurrence of <code>)</code>:</p>
  
  <pre><code>perl -0777 -pe 's/MANAGED BY DATABASE.*\)/MANAGED BY AUTOMATIC STORAGE/sg' temp.txt
  CREATE  TABLESPACE TSASNCA
   IN NODEGROUP IBMCATGROUP
   PAGESIZE 8192
   MANAGED BY AUTOMATIC STORAGE
   EXTENTSIZE 8
   BUFFERPOOL DPROPR8KBP;
  </code></pre>
  
  <p>Not exactly what I wanted. Then I tried to eliminate the greediness and still no luck:</p>
  
  <pre><code>perl -0777 -pe 's/MANAGED BY DATABASE.*\)+?/MANAGED BY AUTOMATIC STORAGE/sg' temp.txt
  CREATE  TABLESPACE TSASNCA
   IN NODEGROUP IBMCATGROUP
   PAGESIZE 8192
   MANAGED BY AUTOMATIC STORAGE
   EXTENTSIZE 8
   BUFFERPOOL DPROPR8KBP;
  </code></pre>