Selecting Groups of elemets

Selecting Groups of elemets

I am trying to easily fix 100+ blog posts where the customer has <pre> tags to format code.
the issue is in wordpress when you hit enter you are given a new <p> tag, and setting the format to preformatted outputs code like this

<pre>line</pre>
<pre>line</pre>
<pre>line</pre>
<pre>line</pre>
<pre>line</pre>

<p> Paragraph Text</p>

<pre>line</pre>
<pre>line</pre>
<pre>line</pre>

I would like to combine each set of pre tags into one ( or wrap each set in a div)

<pre>
    line </br>
    line </br>
    line </br>
    line </br>
    line </br>
</pre>
<p> Paragraph Text</p>
<pre>
    line </br>
    line </br>
    line </br>
</pre>

I have tried

$("pre").wrapAll('<div class="pre"/>');
$("pre").wrapInner('<div class="preline"/>');
$("pre").contents().unwrap();

which works except it combines ALL pre elements into one