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