my $statement = "SELECT name, number, nw, land, strat, last_updated, ownerID FROM someTable ORDER BY number ASC"; $sth = $dbh->prepare($statement); $sth->execute() or die "Can't execute the query: $sth->errstr"; my $ref = $sth->fetchall_hashref('number'); for my $key( %$ref ) { $ref->{$key}->{nw} = addComma( $ref->{$key}->{nw} ); } my $countries = $sth->rows(); $sth->finish; #### my $rows = $dbh->selectall_arrayref("....."); #### my $ref = $sth->fetchall_hashref('number');