use strict;
my $str = 'translate italian ch1_669664cb:| mc
# "Hey."
msgstr "Hey."
translate italian ch1_177d3eb2:| mc
# "What are you doing?"
msgstr "What are you doing?"
translate italian ch1_25d98ea6:| m p_1a
# "I\'m in charge of the breakfast, remember?"
msgstr "I\'m in charge of the breakfast, remember?"
translate italian ch1_7ae83e04:|
# "Oh, that\'s right."
msgstr "Oh, that\'s right."';
my $regex = qr/^(.*)(\|.*)(\n(?:(?!msgstr).*\n)*)(msgstr)/mp;
my $subst = '$1$4$3$2';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html