open my $fh, '<', $filename or die "Can't open $filename: $!\n"; _restore_offset($filename, $fh); while (my $line = <$fh>) { # do stuff here } _record_offset($filename, $fh); close $fh; sub _restore_offset { my ($filename, $fh) = @_; # Get $offset and $last_inode from database my $current_inode = (stat $fh)[1]; return unless $current_inode == $last_inode; seek $fh, $offset, 0; } sub _record_offset { my ($filename, $fh) = @_; my $offset = tell $fh; my $inode = (stat $fh)[1]; # Stuff $offset and $inode back into database }