Perl one-line substitution syntax

Hi,

With the following Perl syntax, how to print the $_ value after the substitution?

s/(\s*|\n)//g foreach (<>);

If I use the below code, it produces some numeric output

print s/(\s*|\n)//g foreach (<>);

In a oneliner:

perl -ne 's/(\s*|\n)//g;print $_' inputfile

Inside a multiline script:

perl -e 's/(\s*|\n)//g && print $_ foreach (<>);' < inputfile
1 Like

perl -npe 's/(\s*|\n)//g;' inputfile see perldoc perlun for details of runtime flags