my $exp = "y=2*x+3"; my %vars = ( x => 1 ); $exp =~ s/([a-z]+)/\$vars{\1}/g; eval $exp; print $vars{ y };