my @Amp = (); #Setting up a dynamic Array due to changes in amounts of possible cell ID's my @Amps = (); #Setting up a dynamic array for the sequences under the IDs my $n = (0); #Array spacer. Not a local variable; used later in execution. my $file2 = shift; open (FILE2, "$file2")|| die "Failed to open $file2 for reading : $!"; # Open first file local $/= ">"; my $first=; while () { # Reading first hash chomp; my ($ID, $Seq) = split("\n"); $Amp[$n] = $ID; #Only need the ID. Sequence can be added to a different array in a similar fashion $Seq =~ tr/acgt/ACGT/; $Amps[$n] = $Seq; #As Above, but the sequence $n++; #Increases array holder } close FILE2 || die "Failed to close $file2 : $!"; ... ... my $m = (0); #New variable to check against Amp while ($m < $n){ #while there remain more Amp ID's to check. Not using <= due to how array and perl interact. foreach my $ID (keys %bwa){ #for each ID ... } $m++; }