# note the use of single quotes $string = 'c:\foo\bar\weird program name.exe' ; # using another regexp separator for readability $string =~ s[foo\\bar][foo\\baz] ; # Or with / as the separator $string =~ s/foo\\bar/foo\\baz/ ;