open FILE, "file" or die "can't open file: $!"; $position{1} = 0; while () { # $. holds line number of file being read from $position{$.+1} = tell(FILE); # record byte offset # do stuff with $_ # access a previous line by doing: if (CONDITION) { seek FILE, $position{$LINE_NUMBER}, 0; $data = ; # ... # when done, get back to where you were seek FILE, $position{$.+1}, 0; } } close FILE;