http://www.perlmonks.org?node_id=550256


in reply to Chomp a numerical expression, return the answer.

Try this:
chomp($exp = <STDIN>); $out = eval $exp; print $out, "\n";
UPDATE: As blazar points out, while this code does what you want, know that it will blissfully run any valid Perl command. You might add some editing of your input before handing it to eval.

Good Luck,

Trix