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 }