use strict; use warnings; my @log = (); while (){ chomp; push @log, $_; if (scalar@log ==3){ do_stuff(\@log); @log = (); } } sub do_stuff{ my $ref = shift; print join ":", @$ref, "\n"; } __DATA__ 1 2 3 4 5 6 #### 1:2:3: 4:5:6: