in reply to Hash of Arrays

Wind pretty much solved the problem correctly. All I have to add is don't forget to close the files you opened.