C:\>perl $pattern = "\\"; $variable = "abcde\\fg"; print $variable =~ /$pattern/; ^D Trailing \ in regex m/\/ at - line 4. #### $variable =~ s/ ( # start capturing to $1 (?: # not capturing, just clustering \Q$pattern\E # $pattern in a quoted way ) + # one or more times ) # end capturing to $1 / .... /x; #### $variable =~ s/((?:\Q$pattern\E)+)/$1.$1.$1/e; print $variable;