In Regexes§

See primary documentation in context for Samecase

The :samecase or :ii substitution adverb implies the :ignorecase adverb for the regex part of the substitution, and in addition carries the case information to the replacement string:

$_ = 'The cat chases the dog';
s:global:samecase[the] = 'a';
say $_;                 # OUTPUT: «A cat chases a dog␤» 

Here you can see that the first replacement string a got capitalized, because the first string of the matched string was also a capital letter.