Strings In Depth18 / 18
Up next

Global substitute

use strict;
use warnings;
use feature 'say';

my $s = "cat hat bat";
# /g replaces every match; ${1} is the capture
$s =~ s/(\w)at/${1}og/g;
say $s;   # cog hog bog
What you're solving

s///g with a capture group