in reply to comparing csv files in perl

You define 5 columns in your output, but your samples have either 3 or 4 columns. The file_3 code is pointless (actually, worse than, because it will cause a compilation error). You need both the fragment and the id from each file, but you store only the first as the hash key.

Perhaps you need to replace the scalar value that indicates which file with a more sophisticated data structure that store all the information you need. Then you can generate your output from the hash values.

1 Peter 4:10