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($rent_hash{$_}[0]$rent_car{$_}[1]%.2f%%\n),$percent; } my $rent_carnor = $result - $rent_carno; my $percent_total = (($rent_carnor / $result) * 100); printf qq(No Response$rent_carnor%.2f%%\n),$percent_total;