in reply to calculate all the data

I think you are confusing the parts your different variables play. Is this what you want?

my $newno = 0; while (my ($number) = $sth->fetchrow_array) { $numbergraf++; # whatever that is $newno += $number; } $output .= qq~ The sum of xxx is $newno ~;

I'm not sure what you're trying to do with substr, but it doesn't look consistent with a sum.

After Compline,
Zaxo