To address you post, the reason I am using two different while loops is because this is the only way from what I know, will compare both files that I am looking at. The nested while loops was the only thing that was working. If there is another way of comparing to files in perl, I am open to changing the script to do so.
The amount of iterations equates to the amount of data within each file, meaning that once every line of each file has been compared to each other, with the appropriate matching statements, then both while loops should stop, and another iteration of the $a from the list should be implicated, thus starting the whole process all over again. The file names from glob function, have a purpose. The gob files contain the names of genome AB files with in the name of the genome BA file name. So when I do the split function on the $a file I will get both file names.
Also to explain why I did a local $/, without it, the whole content of the files wouldn't be upload into the scripts. At one point only the first lines were being compared, so I used the local $/ so that the scalars could have all the content of the files being upload.