use 5.010_001; use strict; use warnings; my $string = "It's hard to teach an old dog new tricks."; $string =~ s/(dog)/reverse($1)/e; say $string;