title: Foreach loop only acting on a portion of the first element in an array
body: <p>I have five fasta files in a directory, which I can successfully put into an array. When I attempt to open all the files in succession via a foreach loop, to perform a regex on each file, only the first file in the directory seems to open for processing. Furthermore, when I try to print the entire sequence in the first file (via a diagnostic print statement not shown), the first half of the sequence is ignored. Only the latter portion of the sequence is printed. If anyone has insights on how to overcome this, I would be very grateful. Here is what my code looks like so far.</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings; 
  use strict;
  use diagnostics; 
  
  my $dir = ("/Users/roblogan/Documents/FakeFastaFilesAgain");  
  my @TrimmedSequences; 
  
  my @ArrayofFiles = glob "$dir/*"; 
  
  #print join("\n", @ArrayofFiles), "\n";      # this is a diagnostic test print statement
  
  foreach my $file (@ArrayofFiles){ 
      open (my $sequence, '&lt;', $file) or die $!; # open each file in the array
      while (my $line = &lt;$sequence&gt;) {  
          $line =~ s/\R//g;                          # get rid of new line breaks
          if ($line =~ m/(CTCCCA)[TAGC]+(TCAGGA)/) { # search file contents 
              push(@TrimmedSequences, $line);        # push the match into another array 
              close $file; 
          }
      }
  }   
  
  print join("\n", @TrimmedSequences), "\n"; 
  </code></pre>