use strict; use warnings; use 5.010; my $data = "greeting"; $data =~ s{greeting} {my $repl = <<"END_OF_STR"; "$repl goodbye mars"; }e; hello world END_OF_STR say $data; --output:-- hello world goodbye mars