my @offsets; sub Set_line (\*\$\$) { my $fh_r=shift @_; my $cur_r=shift @_; my $row_r=shift @_; if ($offsets[$$row_r]){ # We know where the row is, so just go there. seek($ffh_r, $offsets[$$row_r], 0); } elsif ($$cur_r>$$row_r) { # We don't know where it is, so we should start at the end of the area that we've indexed seek ($$fh_r, $offsets[-1],0); $$cur_r= scalar $offsets; } while (!(($$cur_r)==$$row_r) && $_ ne "") { $_=readline($fh_r); $$cur_r++; $offset[$$cur_r] = tell($$fh_r); } return; }