my %rent_hash = (Y=>["Yes",undef], N=>["No",undef]); my $query = "SELECT COUNT(*) FROM owner WHERE rent_car = ?"; my $sth = $dbh->prepare($query); foreach (keys %rent_hash) { $sth->execute($_); my $rent_hash{$_}[1] = $sth->fetchrow_array(); my $rent_carno += $rent_hash{$_}[1]; my $percent = (($rent_car{$_}[1] / $result) * 100); printf qq(