The best solution would be to use a different method of searching. For one, $read() has an option to search for text built right into it. Second, you can use /filter to get what you need. And third, /fseek (after doing /fopen and before doing /fclose) can also be useful.

Any of those 3 options would be considerably faster than looping through all of the lines in a file.