$ perl -we ' > my @values = 1..10; > my $max = 3; > while ( my @parts = splice(@values, 0, $max) ) { > print join ", ", @parts, ( $#parts == 2 ? "\n" : () ); > } > print "\n"; > ' 1, 2, 3, 4, 5, 6, 7, 8, 9, 10