c:\@Work\Perl\monks>perl -MO=Deparse,-p -i -lpe "s/^\s*$/<\/r>/g" BEGIN { $^I = ""; } BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined(($_ = ))) { chomp($_); s[^\s*$][]g; } continue { print($_); } -e syntax OK #### use constant BLANK_LINE => qr{ \A \s* \z }xms; use constant EMPTY_R_PAIR => "\n"; ... $out = EMPTY_R_PAIR if $out =~ BLANK_LINE;