Assuming there are no nested paragraphs ...
my $to_insert = get_thing_to_insert();
$text =~ s/((?:<p>.*?</p>|\n\n){2})/$1$to_insert/s;
should just do it.
With advanced formatting:
$text =~ s{
(
(?:
<p>
.*?
</p>
|
\n\n
){2}
)
}
{$1$to_insert}xms
. \n\n ; Windows, \r\n\r\n, , , \r?\n\r?\n, \r .
, "\n\n" |, <p> - <p> - </p> . , <p> , .