If you only need to traverse the file once, then Bill's posted solution is probably what you should use. If you need to traverse the file several times, then the best method would be to put all the data into a database.

This would be necessary with a large (1.5 GB) file as all the items in a data structure would most likely exceed your RAM memory.

Loading the database for a file this size would probably take as much time as reading through it once. But then lookups should be relatively speedy.

Below are two scripts. One loads the data into the database and the second retrieves the records. I used the SQLite database as it suffices for this problem. You would need to install DBI and DBD::SQLite. The SQLite database is included when you download DBD::SQLite.