Question: Are you sure it's only a single newline that's present? The presence of other whitespace characters than just a newline can confuse the issue. The following might be a better regex: qr{ </div> \s* </body> }xms

Comment on Re^3: Perl RE; how to capture, and replace based on a block?