$bar = "Hello %s world!\n"; if ($bar =~ m/(Hello)/) { $foo = lc $1; $foo =~ s/h/j/; printf $bar, $foo; # prints "Hello jello world!" }