quote s/ / /

Documentation for quote s/ / /, assembled from the following types:

language documentation Regexes

From Regexes

(Regexes) quote s/ / /

Substitutions are written similarly to matching, but the substitution operator has both an area for the regex to match, and the text to substitute:

s/replace/with/;           # a substitution that is applied to $_ 
$str ~~ s/replace/with/;   # a substitution applied to a scalar 

The substitution operator allows delimiters other than the slash:

s|replace|with|;
s!replace!with!;
s,replace,with,;

Note that neither the colon : nor balancing delimiters such as {} or () can be substitution delimiters. Colons clash with adverbs such as s:i/Foo/bar/ and the other delimiters are used for other purposes.

If you use balancing brackets, the substitution works like this instead:

s[replace] = 'with';

The right-hand side is now a (not quoted) Perl 6 expression, in which $/ is available as the current match:

$_ = 'some 11 words 21';
s:g[ \d+ ] =  2 * $/;
.say;                    # OUTPUT: «some 22 words 42␤» 

Like the m// operator, whitespace is ignored in the regex part of a substitution. Comments, as in Perl 6 in general, start with the hash character # and go to the end of the current line.