Newline removed after, not before | | | | v v 's/\n^$|\n^dn:*$//mg','s/cn: //g','s/\norclnetdescstring: /=/g' 's/\n^$|^dn:.*\n//mg; s/cn: //g; s/\norclnetdescstring: /=/g ^ ^ | | Missing | dot Optional: no need to switch between Perl and shell, using semicolons instead of commas.