syntax s/ / /
Documentation for syntax s/ / /
assembled from the following types:
language documentation Regexes
From Regexes
(Regexes) quote s/ / / 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 $_~~ 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 curly braces, square brackets, or parentheses, 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.