in reply to How to deal with Huge data

So you are joining two files on a common field?

That looks like you want to use DBD:CSV, which deals with text databases. Your code turns into a single SQL query. Handling of variable column order comes for free, as DBD::CSV reads the names from the first line in the file.