$replace = '$1 thirdword'; ($varsub = $string) =~ s/$search/$replace/; #### $replace = '$1 . " thirdword"'; ($varsub = $string) =~ s/$search/$replace/ee;