use DBI; use Benchmark; use strict; use warnings; my $dsn = "dbi:mysql:database"; my $dbh = DBI->connect("$dsn",'user','password', { RaiseError => 1, } ); my $statement = qq~SELECT field1, field2, field3 FROM table~; my $key_field = 'table_id'; timethese( 1_000, { array_way => sub { $ary_ref = $dbh->selectall_arrayref($statement) }, hash_way => sub { $hash_ref = $dbh->selectall_hashref($statement, $key_field) } } );