#You might want to do something to look for say sin, cos, tan, etc. unless( $str =~ /[^0-9+-*^/.,_()]/ ){ eval($str); }