I have the following structure.
var i, num = 3, $ul = $('#ul'), $li = $('#ul > li');
for (i=0;i<$li.length;i+=num) {
$li.slice(i,i+num).wrapAll('<ul />');
}
$ul.find('> ul').unwrap();
http://jsfiddle.net/Q2bYz/
You can do it with wrapAll:
var a = $('li');
do $(a.slice(0,3)).wrapAll('<ul />');
while((a = a.slice(3)).length>0)
example: http://jsfiddle.net/niklasvh/mZr4h/
.wrap() api is what you are looking for