On the basis of replace text with function ? and similar, a version of s///(g) that takes a code ref as the second half of the construct (somehow) and calls the subroutine with @_ aliased to the current captures:
sub transform (
$_[ 0 ] = 'tripped';
}
...
$text =~ s[cow\s+(jumps)\s+over][\&transform]rg; ## /r for 'ref'?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.