As an aside, you probably want to use last rather than exit. The former exits the loop, while the latter exits the program. You never reach close FLAT_FILE; as it is now. The close isn't necessary, but this misdirection might cause you problems in the future.