title: Split file contents into 2 arrays based on a key word
body: <p>I have a file which has something like</p>
  
  <pre><code>line1
  line2
  line3
  line4
  .endm
  line5
  line6
  line7
  line8
  .endm
  </code></pre>
  
  <p>I want to split this file at .endm and put the contents in 2 different arrays. Output would be </p>
  
  <pre><code>@array1=(line1,line2,line3,line4);
  @array2=(line4,line6,line7,line8);
  </code></pre>
  
  <p>I tried using </p>
  
  <pre><code>@array = split(".endm",my_file.txt);
  print("Array1 = $array[1]\nArray2 = $array[2]\n);
  </code></pre>
  
  <p>But this just prints out the line number of the last .endm</p>
  
  <p>I also tried something like </p>
  
  <pre><code>#! /usr/intel/bin/perl -w
  use strict;
  
  my $count=0;
  open(my $fh, "&lt;", "a.txt")|| die "can't open UTF-8 encoded filename: $!";
  my @lines = &lt;$fh&gt;;
  my @array;
  
  LOOP: foreach my $line (@lines) {
      chomp ($line);
      $count = $count+1;
      push (@array,$line);  
      if ($line =~ m/.endm/) {
          pop (@array);
          last LOOP;
      }
  }
  print("Array : @array\n");
  close $fh;
  </code></pre>
  
  <p>This one prints <code>@array=(line1,line2,line3,line4);</code> But I still need the other 4 lines so that I can put it in a different array</p>
  
  <p>So how do I go about splitting a file based on some keyword?</p>