use strict; use warnings; my $str = <\n

$2/gsi; $str =~ s/^(<\/p>)\n*(.+)$/$2$1/gsi; print $str;