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