Perl command line search and replace with multiple expressions

perl

Solution

Several `-e`'s are allowed.

You are missing the `';'`

find "*.cpp" | xargs perl -i -pe 's/##(\W)/\1/g;' -pe 's/(\W)##/\1/g;'

Perl statements has to end with `;`. Final statement in a block doesn't need a terminating semicolon. So a single `-e` without `;` will work, but you will have to add `;` when you have multiple `-e` statements.

Problem

I am using Perl to search and replace multiple regular expressions: When I execute the following command, I get an error: ``` prompt> find "*.cpp" | xargs perl -i -pe 's/##(\W)/\1/g' -pe 's/(\W)##/\1/g' syntax error at -e line 2, near "s/(\W)##/\1/g" Execution of -e aborted due to compilation errors. xargs: perl: exited with status 255; aborting ``` Having multiple `-e` is valid in Perl, then why is this not working? Is there a solution to this?

Original source