in reply to multi-line RE question

Perhaps you intended to stick to Perl... but what you posted doesn't seem to do so as the printf seems to be a nix-ish shell command.

Try, instead, this (and excuse the windows shell syntax and avoidance of file ops):

C:\_wo>perl -e "my $line = \"Line1\nLine2\nLine3\n\nXYZ: Blah\n\"; $li +ne =~ s|\nXYZ.+\n||m; print $line;" Line1 Line2 Line3 C:\_wo>

OTOH, if I misunderstood your question, please correct me.