Please don't ask me to do any Lisp code (I havnen't in years and wouldn't be of any use) but if I may make a suggestion:
Read the contents of the file into a list and check the items in the list. The reason being it would be faster if you read contents and operate on a list instead of trying to check as you are reading the file.
I do have these snips of code you can use (left over from my lisping days):
(defun file
-get
-list
-from
( name
/ fp lst read
-file
-into
-list ) ;;/*{{{*/ ;; file-get-list-from
;;
;; GENERAL FILE READER
;; given a file name this procedure will read the contents
;; into a list
;;
;; EX:
;; (mapcar
;; 'read (get-list-from-file
;; (findfile layers-to-load-from-file)))
;;
;; By: John K
;;
(defun read
-file
-into
-list ( str file
) ;;/*{{{*/ lst ) ;;/*}}}*/
(defun =|
( a l
) ;; /*{{{*/ ;; notequal
;;
;; preform a equality test on a given object and
;; a list of items.
;;
;; Example: (setq a 1 b 2 c 3 d 4 e 5 f 1)
;; (=| a '(b c d e f))
;; > T
;;
;; (=| a '(b c d e))
;; > nil
;;
;; By: John K
;; 01.06.06
;;
;; Notes:
;; If your testing variables you cant just do a ``member ...list''
;;
;; If your wanting to test variables your going to have to do something
;; like this (using the var's i set up in the example)
;;
;; (and (member (eval a) (mapcar 'eval '(b c d e f))))
;;
;; Because a simple
;; (and (member a '(b c d e f)))
;;
;; will return nil
;;
T
(= a
(eval x
)))) l
))) ) ;; /*}}}*/
I hope my analysis of your code wasn't too far off base (very rusty at reading lisp code) and these procedures help a little.