use Benchmark; for $SIZE (100, 1000, 10000) { timethese(-5, { sp_fr_pu => sub { my @a = (1..$SIZE); my @b; while (my @c = splice(@a, 0, 4)) { push @b, { @c } } }, sp_bk_un => sub { my @a = (1..$SIZE); my @b; while (@a and my @c = splice(@a, -4)) { unshift @b, { @c } } }, sp_bk_in => sub { my @a = (1..$SIZE); my @b; $#b = int(@a / 4); my $i = $#b; while (@a and my @c = splice(@a, -4)) { $b[$i--] = { @c } } }, in_fr_pu => sub { my @a = (1..$SIZE); my @b; my $i = 0; while ($i < @a) { push @b, { @a[$i .. $i + 3] }; $i += 4; } }, sh_fr_pu => sub { my @a = (1..$SIZE); my @b; while (@a) { push @b, { map shift(@a), 1..4 } } }, sp_bk_rv => sub { my @a = (1..$SIZE); my @b; while (@a and my @c = splice(@a, -4)) { push @b, { @c } } @b = reverse @b; }, }); }