title: Perl: how to split a file?
body: <p>I need to split a file into different ones.</p>
  
  <p>Exmaple (original file):</p>
  
  <pre><code>*****3123123*****RAW
  text1
  text2
  *****2312354***RAW
  text3
  </code></pre>
  
  <p>Desired output:</p>
  
  <p>[File1.txt]</p>
  
  <pre><code>*****3123123*****RAW    
  text1
  text2
  </code></pre>
  
  <p>[File2.txt]</p>
  
  <pre><code>*****312312354***RAW
  text3
  </code></pre>
  
  <p>I tried to use split, but I always get some extra white characters into the array</p>
  
  <pre><code>open FILE, "&lt;file";
  @file= &lt;FILE&gt;;
  close FILE;
  @lines = split (/(RAW\n)/, "@file");
  foreach $value (@lines) {
    if ($value =~ /[a-z]|[A-Z]|[1-9]/)  {
      print ("$value\n");
    }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>*****3123123*****RAW
  
   text1
   text2
  
  *****312312354***RAW
  
   text3
  </code></pre>
  
  <p>Edit: if I use print ("$value") instead of print ("$value\n") this is the output (notice the 1 extra space before the value:</p>
  
  <pre><code>*****3123123*****RAW
   text1
   text2
  
   *****12354***RAW
   text3
  </code></pre>