in reply to point to previous line

You can also use a queue.

All off-hand code.

my @q[0..1] = ( "\n" x 2); # other initialization may be apropos while (1) { @q[0..1] = ($q[1], scalar( <INPUT>)); last if not defined $q[1]; # previous line is $q[0] # currentline is $q[1] do_something(\@q); } # current line, the last line is now in $q[0]

Something like this may be used to empty the queue inside the loop. Replace the line with "last" with this:

# handle last line in loop if ( not defined $q[1] ) { $q[1] = $q[0]; $q[0] = "\n"; do_something( \@q); last; }