$ perl -e ' $x = 1; if( $x ) { print map { s{^ }{}gm; $_ } <<" EOT"; Line 1 Line 2 \$x is $x Line 4 EOT }' Line 1 Line 2 $x is 1 Line 4 $