in reply to perl code for linear regression

For heavy duty statistics you can use RSPerl which is a way to call the R language from Perl. I started using it to do kernel density estimation. You can find the software Here