If you really want to use a shell script consider chaining in the % wc -l command. That way you could have the first line be the number of lines you have to process. Even better, follow one of the suggestions others have made about opening the file from within perl.
Want to support the EFF and FSF buy buying cool stuff? Click here.