use strict; use warnings; use Benchmark qw(cmpthese); my %hash = ( 1 => 'one' , 2 => 'two' , 3 => 'three' ); cmpthese (-1, { 'orig' => sub {orig ()}, 'roy' => sub {roy ()}, 'GF' => sub {GF ()}, 'VS' => sub {VS ()}, 'davido' => sub {davido ()}, 'sneekyGF' => sub {sneekyGF ()}, 'sneekyDuff' => sub {sneekyDuff ()}, } ); sub orig { my (@one, @two); foreach ( keys %hash ) { push @one , $hash{$_}; push @two, $_; } } sub roy { my (@one, @two); push @one, values %hash; push @two, keys %hash; } sub GF { my (@one, @two); (push @one , $hash{$_}), push @two, $_ foreach ( keys %hash ); } sub VS { my (@one, @two); @one = values %hash; @two = keys %hash; } sub davido { my( @one ) = @hash{ my( @two ) = keys %hash }; } sub sneekyGF { my (@one, @two); --$| ? push @one, $_ : push @two, $_ foreach %hash; } sub sneekyDuff { my (@one, @two); push @{--$| ? \@one : \@two}, $_ for %hash; } sub BUK { my (@one, @two); 1 while ( $one[@one], $two[@two] ) = each %hash; }