use Benchmark qw( cmpthese ); my @input = ( 'x' x 100 ) x 1_000_000; sub copy_array { my @copy = @{$_[0]}; return @copy; } sub copy_grep { my @copy = grep /x/, @{$_[0]}; return @copy; } sub return_grep { return grep /x/, @{$_[0]}; } sub return_scalar_grep { return scalar grep /x/, @{$_[0]}; } sub bare_grep { grep /x/, @{$_[0]} } sub bare_scalar_grep { scalar grep /x/, @{$_[0]} } sub bare_list_grep { () = grep /x/, @{$_[0]} } cmpthese 100, { copy_array => sub { copy_array( \@input ) }, copy_grep => sub { copy_grep( \@input ) }, return_grep => sub { return_grep( \@input ) }, return_scalar_grep => sub { return_scalar_grep( \@input ) }, bare_grep => sub { bare_grep( \@input ) }, bare_scalar_grep => sub { bare_scalar_grep( \@input ) }, bare_list_grep => sub { bare_list_grep( \@input ) }, }; __END__ Rate copy_grep copy_array bare_list_grep return_scalar_grep return_grep bare_scalar_grep bare_grep copy_grep 1.23/s -- -21% -39% -78% -79% -79% -79% copy_array 1.56/s 27% -- -23% -73% -73% -73% -74% bare_list_grep 2.02/s 65% 30% -- -64% -65% -65% -66% return_scalar_grep 5.69/s 363% 265% 181% -- -2% -2% -4% return_grep 5.78/s 371% 271% 185% 2% -- -1% -3% bare_scalar_grep 5.82/s 374% 274% 188% 2% 1% -- -2% bare_grep 5.93/s 383% 280% 193% 4% 3% 2% --