If you can fit the first file into a hash (key: first field, value: full line), then you don't even need to use the sort function: load file 1 into the hash, read file 2 and, for each line of file 2, lookup into the hash with the key, print the line from the hash, delete the hash record; at the end, print out the hash records still there.