while (my $hr = $S->fetchrow_hashref) { my $cur_total = $hr->{Quantity} * $hr->{Unit_Price}; my $cur_tax = 0; $cur_tax = $cur_total * $hr->{Tax_Rate} if $hr->{Taxable} eq 'Y'; ... }