in reply to Can we do without auxiliary variable here?
I'm not sure that extracting things is the right approach. Instead I'd try to replace all newlines with \n$prefix (resp. all "starts" of the string with the prefix, in REspeak):
sub prefix_print { # unfortunately, the local copy of $_ is necessary to be able to p +refix_print # constants print map { my $l = $_; $l =~ s/^/$prefix/gm; $l } @_ }; prefix_print qq(foo\nbar),2,3,4
|
|---|