Thanks MidLifeXis for your quick response. Here are the answers to your questions:
file2 is sorted by the key value, but I think I can sort file1 before processing it.
Depends on the date, the content of file1 and file2 might change. And for module DBM::Deep, because it is an old Unix environment, DBM::Deep is not available, and I don't have the permission to install it. :(
Yes, these records are fixed size, I am gonna try binary search.