while (@a) { my @group = splice(@a, 0, 3); ... }