I know that you don't want to slurp the file into an array, but this is really a perfect place to use
Tie::File. Even the FAQ says so. It is much faster and memory efficient than slurping, so it isn't really "resorting to assigning the file to an array first and push'in the line in."
HTH.
Edited for Clarity