use strict; use warnings; use Benchmark qw/cmpthese/; my @matrix = ( [ 1, 2, 3, 4, 5, ], [ 6, 7, 8, 9, 10, ], [ 11, 12, 13, 14, 15, ], [ 16, 17, 18, 19, 20, ], [ 21, 22, 23, 24, 25, ], ); cmpthese( 50000, { onemap => sub{ my $result = onemap( \@matrix ); }, twomaps => sub{ my $result = twomaps( \@matrix ); }, } ); sub onemap { my $matrix = shift; return { Matrix => [ map { [ @$_ ] } @$matrix ] }; } sub twomaps { my $matrix = shift; return { Matrix => [ map { my $row = $_; [ map { ( $_ ); } @$row ] } @$matrix ] }; } __END__ Rate twomaps onemap twomaps 62814/s -- -39% onemap 103306/s 64% --