FASTA: for (my $h=0;$h<(@fastarray);$h++) { $setscounter = 0; if (defined %{$matches{$fastarray[$h]}}){ SITE: for $site (sort {$a <=> $b } keys %{$matches{$fastarray[$h]}}) { if (@{$matches{$fastarray[$h]}{$site}}) { $i = 0; ELEM: while ($i < length(@{$matches{$fastarray[$h]}{$site}})) { $lowerlimit = 0; my $low = $matches{$fastarray[$h]}{$site}[$i]; $lowerlimit = $low + 0; $upperlimit = $span + $lowerlimit; SITEKEY: for $sitekey (sort {$a <=> $b } keys %{$matches{$fastarray[$h]}}) { if (@{$matches{$fastarray[$h]}{$sitekey}}) { my @arrayA = (); my $hit = 0; SET: while ($hit < length(@{$matches{$fastarray[$h]}{$sitekey}} )) { print "...in \$matches{$fastarray[$h]}{$sitekey}[$hit]\n"; if ($matches{$fastarray[$h]}{$sitekey}[$hit] >= $lowerlimit && $matches{$fastarray[$h]}{$sitekey}[$hit] <= $upperlimit) { push (@arrayA, $matches{$fastarray[$h]}{$sitekey}[$hit]); $hit++; next SET; #closes If setcount } elsif ($matches{$fastarray[$h]}{$sitekey}[$hit] < $lowerlimit) { $hit++; next SET; } else {$hit++;} #closes while hit } if (@arrayA && $hit == length(@{$matches{$fastarray[$h]}{$sitekey}})) { $sets{$fastarray[$h]}[$setscounter]{$sitekey} = \@arrayA; print "\$sets{$fastarray[$h]}[$setscounter] is:\n"; print Dumper(%{$sets{$fastarray[$h]}[$setscounter]}); @arrayA = (); } else { $sets{$fastarray[$h]}[$setscounter]{$sitekey} = undef; } $hit = 0; next SITEKEY; #closes if matches } next SITEKEY; #closes SITEKEY } $setscounter++; $i++; next ELEM; # closes while i } #closes if matches } next SITE; #closes for my site } #closes if defined } next FASTA; #closes for fastarray } #### ...in $matches{>scaffold_446}{0}[1] $sets{>scaffold_446}[1] is: $VAR1 = '0'; $VAR2 = [ 0, # These 2 array elements should not BOTH 0 # be 0!!! What did I do wrong? ]; ...in $matches{>scaffold_446}{1}[0] ...in $matches{>scaffold_446}{2}[0] ...in $matches{>scaffold_446}{0}[0] ...in $matches{>scaffold_446}{0}[1] ...in $matches{>scaffold_446}{1}[0] $sets{>scaffold_446}[2] is: $VAR1 = '1'; # For each of these different '...in $matches..." $VAR2 = [ # There should be 6 $VAR variables. corresponding 40048 # to 3 key/value pairs, but I am doing something wrong ]; # in my code, such that sometimes there are 3 pairs, but $VAR3 = '0'; # often not. Any thoughts? $VAR4 = undef; ...in $matches{>scaffold_446}{2}[0] ...in $matches{>scaffold_446}{0}[0] ...in $matches{>scaffold_446}{0}[1] ...in $matches{>scaffold_446}{1}[0] ...in $matches{>scaffold_446}{2}[0] $sets{>scaffold_446}[3] is: $VAR1 = '1'; $VAR2 = undef; $VAR3 = '0'; $VAR4 = undef; $VAR5 = '2'; $VAR6 = [ 5468 ]; ...in $matches{>scaffold_3198}{0}[0] $sets{>scaffold_3198}[0] is: $VAR1 = '0'; $VAR2 = [ 1829 ];