.... my $sth = $dbh->prepare($sql); $sth->execute() || die $sth->errstr; #test values here::: #use Data::Dumper; #my $array_ref = $sth->fetchall_arrayref; #print Dumper $array_ref; #end test::: my $array_ref = $sth->fetchall_arrayref(); foreach $row (@$array_ref) { ($type, $total) = @$row; if ($type eq "A"){$a = $total;} if ($type eq "B"){$b = $total;} if ($type eq "C"){$c = $total;} if ($type eq "D"){$d = $total;} if ($type eq "W"){$w = $total;} } $total = $a + $b + $c + $d + $w; print "$w\n"; print "$total\n";