my $p; while(){ #du stuff if( prevous line needed and defined $p ){ seek FILE, -(length()+$p), 1; my $prevous_line = ; # next will return the current line again, # so call it again before going on! } } continue { $p = length() }