in reply to Math in Template::Toolkit

I am willing to beat the error is further up the script than what you have shown us. The line you showed us is where the compiler decided were it thought the error was, not where the error actually is

Consider moving your code out of the template and into a plugin. It would easier to read your template and I find it easier to debug Perl code rather than templates that do not compile.