#!/usr/bin/perl -- use strict; use warnings; my $blah = q{-0.137 + (0.00479 / (W/0.9)) + (2.5593 * (W/0.9 ) ,0.045,0 }; print EvalPolynominal( $blah, 1,1 ); sub EvalPolynominal { #first parameter gives the polynominal string #second parameter gives the min-des width #third parameter gives the short-line length my $polynominal = shift; my $curWidth = shift; my $curLength = shift; $polynominal =~ s/W/$curWidth/g ;#replace W with current value of min width $polynominal =~ s/L/$curLength/g ;#replace L with current value of min Length local $@; my $ret = eval $polynominal; warn "Trying:\n\t$polynominal\nbut got: $@\n" if $@; return $ret; } __END__ $ perl -we " -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045,0 " syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. $ perl blah Trying: -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045,0 but got: syntax error at (eval 1) line 2, at EOF Use of uninitialized value in print at blah line 4. $ perl -we " -0.137 + (0.00479 / (1/0.9)) + (2.5593 * (1/0.9 ) ,0.045,0 " syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors.