I suppose this sounds crazy (might be retrograded suggestion even), how about reading in the whole file content as an array and using
... venerated ones here might be able to let you know the cons of such an action (personally I feel that breaking up the file into an appropriate database in mysql and querying that database will free you of a lot of work ... but I guess you know better :-) ).