$abc = 999; $string = 'abcdefgh%$abc%ijkl'; $string =~ s/\%\$([A-Za-z][A-Za-z0-9_]*)\%/${$1}/e; print $string;