my $text = "Here is some\nmulti-lined text"; my $insert = "thrilling " $text =~ s/(some\s)/$1$insert/s;