Here's my solution, it also handles the more deeply nested cases like <r><p>a<x>b<y>c<x>d<s/>e</x>f</y>g</x>h</p></r>:
use warnings;
use strict;
use XML::LibXML;
my $dom = XML::LibXML->load_xml(string => <<'END_XML');
<?xml version="1.0"?>
<office:document-content office:version="1.2"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">
<office:body><office:text>
<text:p text:style-name="P1">
Fo<text:span text:style-name="T1">o<text:line-break/>B</text:span>
<text:span text:style-name="T3">a</text:span>
<text:span text:style-name="T5">r<text:line-break/></text:span>
</text:p>
</office:text></office:body>
</office:document-content>
END_XML
my $xpc = XML::LibXML::XPathContext->new($dom);
$xpc->registerNs('office',
'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xpc->registerNs('text',
'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
my $breakat = 'text:line-break';
my $ancestor = 'text:p';
while (1) {
my ($br1) = $xpc->findnodes("//$ancestor//${breakat}[1]") or last;
die "can't handle <$breakat> with children: $br1"
if $br1->hasChildNodes;
my ($an1) = $xpc->findnodes("ancestor::${ancestor}[1]",$br1)
or die "failed to find <$ancestor> ancestor of $br1";
my $an2 = $an1->cloneNode(1);
my ($br2) = $xpc->findnodes(".//${breakat}[1]", $an2)
or die "internal error: failed to find <$breakat> in $an2";
for ( my $cur = $br1; $cur!=$an1 ; $cur = $cur->parentNode ) {
while ( my $s = $cur->nextSibling )
{ $s->unbindNode }
}
$br1->unbindNode;
for ( my $cur = $br2; $cur!=$an2 ; $cur = $cur->parentNode ) {
while ( my $s = $cur->previousSibling )
{ $s->unbindNode }
}
$br2->unbindNode;
$an1->parentNode->insertAfter($an2, $an1);
}
print $dom;
__END__
<?xml version="1.0"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument
+:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:
+text:1.0" office:version="1.2">
<office:body><office:text>
<text:p text:style-name="P1">
Fo<text:span text:style-name="T1">o</text:span></text:p><text:p te
+xt:style-name="P1"><text:span text:style-name="T1">B</text:span>
<text:span text:style-name="T3">a</text:span>
<text:span text:style-name="T5">r</text:span></text:p><text:p text
+:style-name="P1"><text:span text:style-name="T5"/>
</text:p>
</office:text></office:body>
</office:document-content>