in reply to RandomFile

The only way to do what you want is read the entire file. To quote a line from Advanced Perl Programming. (In general, since line lengths vary, it's not possible to access a particular line number without examining the whole file up to that line number, unless all your lines are known to be of a particular length, or you've built an index that translates line numbers into byte offsets.) --eric