in reply to inefficient code? works on small files ok but not larger ones

well, depending on what the specs of your machine is. I'd say that
@file = <FILE>;
could be part of the problem. Especially if you have limited RAM.