$string = 'string with word foo in it'; $string =~ s/(foo)/\1bar/g; #### $string = 'string with word foo in it'; $find = '(foo)'; $replace = '\1bar'; $string =~ s/$find/$replace/g;