in reply to open and read file using cgi perl

Given the simplicity of what you want to compare, your code seems to me to be far too complicated. I don't feel like dwelling into your code, but, setting aside the HTML output, I feel the whole comparison part could probably be done in less than 20 lines of code. But you don't really state what you want to do.

An important question: how large are your files? Reading the complete second file for each line of input in the first file is most probably extremely inefficient. One of the most common way to do this type of thing is to store one of the files (often the smallest one, but not necessarily) in an appropriate data structure, often a hash or something similar, so that you can then read the other file line by line and access instantly to the data you need for the comparison. But this is not possible if your files are really huge and will exhaust memory.

If the files are really too large for that (i.e. the file won't fit into memory), there is still another possibility: sort both files according to the comparison key, and read them in parallel.

But don't read one file for each input line of the other. This is extremely inefficient.