$sth=$dbh->prepare(qq{select id, quotient from ergebnis order by id}); $sth->execute(); my $array_ref=$sth->fetchall_arrayref(); my %hash; foreach my $row (@$array_ref) { #split the row my ($id, $quotient) = @$row; $hash{$id} += $quotient; print "$id\t$quotient\n"; }