Well it sounds like you are trying to reinvent the wheel here why not take a look at File::Compare or try out Array::Compare I think this will be the easiest and fastest for you.
SUNADMN USE PERL
Comment on Re: search a line in a file of 60,000 lines