$var = 'aba'; $regEx = 's/a/A/g'; printf("before: $var\n"); eval("\$var =~ $regEx"); printf("after : $var\n");