title: Count the number of items derived from split without putting into an array
body: <p>I am looking to spare the use of an array for memory's sake, but still get the number of items derived from the split function for each pass of a while loop.<br>
  The ultimate goal is to filter the output files according to the number of their sequences, which could either be deduced by the number of rows the file has, or the number of carrots that appear, or the number of line breaks, etc. 
  Below is my code:  </p>
  
  <pre><code>    #!/usr/bin/perl
      use warnings; 
      use strict; 
      use diagnostics; 
  
      open(INFILE, "&lt;", "Clustered_Barcodes.txt") or die $!;
  
      my %hash = ( 
              "TTTATGC" =&gt; "TATAGCGCTTTATGCTAGCTAGC",
              "TTTATGG" =&gt; "TAGCTAGCTTTATGGGCTAGCTA",
              "TTTATCC" =&gt; "GCTAGCTATTTATCCGCTAGCTA",
              "TTTATCG" =&gt; "AGTCATGCTTTATCGCGATCGAT",
              "TTTATAA" =&gt; "TAGCTAGCTTTATAATAGCTAGC",
              "TTTATAA" =&gt; "ATCGATCGTTTATAACGATCGAT",
              "TTTATAT" =&gt; "TCGATCGATTTATATTAGCTAGC",
              "TTTATAT" =&gt; "TAGCTAGCTTTATATGCTAGCTA",
              "TTTATTA" =&gt; "GCTAGCTATTTATTATAGCTAGC",
              "CTTGTAA" =&gt; "ATCGATCGCTTGTAACGATTAGC",
      );
  
      while(my $line = &lt;INFILE&gt;){ 
              chomp $line; 
              open my $out, '&gt;', "Clustered_Barcode_$..txt" or die $!;
              foreach my $sequence (split /\t/, $line){
                      if (exists $hash{$sequence}){
                          print $out "&gt;$sequence\n$hash{$sequence}\n";
                      } 
              }
      }
  </code></pre>
  
  <p>The input file, "Clustered_Barcodes.txt" when opened, looks like the following:   </p>
  
  <pre><code>    TTTATGC TTTATGG TTTATCC TTTATCG
      TTTATAA TTTATAA TTTATAT TTTATAT TTTATTA
      CTTGTAA 
  </code></pre>
  
  <p>There will be three output files from the code, "Clustered_Barcode_1.txt", "Clustered_Barcode_2.txt", and "Clustered_Barcode_3.txt". An example of what the output files would look like could be the 3rd and final file, which would look like the following: </p>
  
  <pre><code>    &gt;CTTGTAA 
      ATCGATCGCTTGTAACGATTAGC 
  </code></pre>
  
  <p>I need some way to modify my code to identify the number of rows, carrots, or sequences that appear in the file and work that into the title of the file. The new title for the above sequence could be something like "Clustered_Barcode_Number_3_1_Sequence.txt" </p>
  
  <p>PS- I made the hash in the above code manually in attempt to make things simpler. If you want to see the original code, here it is. The input file format is something like: </p>
  
  <pre><code>   &gt;TAGCTAGC 
      GCTAAGCGATGCTACGGCTATTAGCTAGCCGGTA  
  </code></pre>
  
  <p>Here is the code for setting up the hash: </p>
  
  <pre><code>    my $dir = ("~/Documents/Sequences");          
      open(INFILE, "&lt;", "~/Documents/Clustered_Barcodes.txt") or die $!; 
  
      my %hash = (); 
  
      my @ArrayofFiles = glob "$dir/*";            #put all files from the specified directory into an array
  
      #print join("\n", @ArrayofFiles), "\n";       #this is a diagnostic test print statement
  
      foreach my $file (@ArrayofFiles){                                 #make hash of barcodes and sequences
          open (my $sequence, $file) or die "can't open file: $!";        
          while (my $line = &lt;$sequence&gt;) {    
              if ($line !~/^&gt;/){ 
                  my $seq = $line; 
                  $seq =~ s/\R//g;
                  #print $seq;           
                  $seq =~ m/(CATCAT|TACTAC)([TAGC]{16})([TAGC]+)([TAGC]{16})(CATCAT|TACTAC)/;  
                  $hash{$2} = $3;                    
              }
          }
      } 
  
      while(&lt;INFILE&gt;){ 
  </code></pre>
  
  <p>etc</p>