You have two choices. Either you can save the whole file in an array, with one line per array element, in which case you can just refer to $array[30], or else on the way by you can use tell to find out where you are right before you read a line, then use seek to go back there.