in reply to Perl and maths
As rg0now and hardburn have alluded to, such coding has been done. For a historical referent, look up MACSYMA, which does what you want and much more, including much of Calculus and DiffEq. The original LISP code was floating around an MIT server at one time... it's really elegant.
Math::Symbolic can be whacked to print your intermediate results.