My Math::Symbolic module uses code generation to "compile" the function that a Math::Symbolic tree represents to Perl code and/or an anonymous sub. The LaTeX dumper generates LaTeX on the fly, too.
For example: (untested)
in reply to Code Generation with Perl?
Nonetheless, it's usually considered a bad idea to generate code if you can do it someway else. Consider using anonymous subs instead.
use Math::Symbolic qw/:all/;
my $function = parse_from_string(
my ($closure) = $function->apply_derivatives()->to_sub();
print $closure->(5, 3, 1); # A=5, omega=3, t=1
my ($code) = $function->apply_derivatives()->to_code();
print $function->to_latex(replace_default_greek => 1);