The simple fix suggested by
RichardK is working, but is not a very efficient way to do such a thing, as pointed by
RichardK himself. It is usually better to load at least one of the files into memory (as an array, a hash or some other data structure, but, as Richard already asked, we would need to know how large your two files are in order to be able to provide more guidance on how to do it.