my @lines; while (<>) { push @lines, $_; next if $. % 3; ... @lines = (); } die if @lines;