#!/usr/bin/perl use strict; use warnings; while() { my $len = length($_); chomp; push ( my @three, $_ ); # Grab next two lines in file my $c; CALL: while () { chomp; last CALL if $c++ == 2; push ( @three, $_ ); } # Do stuff to process @three print $_,"\t" for ( @three ); print("\n"); # Rewind or stop eof(DATA) ? last : seek(DATA, -($len*3), 1); } __DATA__ 1 2 3 4 5 6