for (my $y = 0; $y < $num; $y++) { for (my $x = $y+1; $x < $num; $x++) { if (($scores->[$y]->[$x] >= 0.96)) { if ($blast_par->{$cleancodes->[$x]}->{"taxon"} eq $blast_par->{$cleancodes->[$y]}->{"taxon"}) { if (($blast_par->{$cleancodes->[$y]}->{"defline"} =~ m/refseq/i) && ($blast_par->{$cleancodes->[$x]}->{"defline"} =~ m/refseq/i)) { if ($blast_par->{$cleancodes->[$y]}->{"defline"} =~ m/NP_/) { # this line produces the error $to_keep = $y; $to_kill = $x; } elsif (($blast_par->{$cleancodes->[$y]}->{"defline"}->[$y] !~ m/NP_/) && ($blast_par->{$cleancodes->[$x]}->{"defline"}->[$x] =~ m/NP_/)) { $to_keep = $x; $to_kill = $y; } } &generic_sub($to_kill, $to_keep); } } } }