Keep It Simple, Stupid  
PerlMonks 
Re: calculate ChiSquare testby moklevat (Priest) 
on Feb 06, 2013 at 15:02 UTC ( #1017451=note: print w/ replies, xml )  Need Help?? 
To add to blue_cowdawg's advice, if you need to roll your own, what you are seeking is the probability density function of the chisquared distribution, which is given here where x is the chisquare value and k is the number of degrees of freedom, and you will need to include values from the Gamma function, which has a closed form solution for halfinteger value (i.e. k/2).
In Section
Seekers of Perl Wisdom

