title: How to print all lines between certain matching string to a different file in perl
body: <p>am fairly new to the perl scripting and need some help. below is my query:</p>
  
  <p>I have a file which has contents like below:</p>
  
  <pre><code>AA ABC 0 0 
  line1
  line2
  ...
  AA XYZ 1 1
  line..
  line..
  AA GHI 2 2
  line..
  line...
  </code></pre>
  
  <p>Now I would like get all the lines between those lines which have the starting string/pattern <code>"AA"</code> and write them to files <code>ABC.txt</code>, <code>XYZ.txt</code>, <code>GHI.txt</code>, repsectively including the line <code>AA*</code>, for examples <code>ABC.txt</code> should look like</p>
  
  <pre><code>AA ABC 0 0
  line1
  line2...
  </code></pre>
  
  <p>and <code>XYZ.txt</code> should look like</p>
  
  <pre><code>AA XYZ 1 1
  line..
  line..
  </code></pre>
  
  <p>Hope am clear in this question and any help regarding this is much appreciated.</p>
  
  <p>Thanks,
  Sandy</p>