sub _move { my $did_something = 0; foreach my $descendant ( $_[1]->descendants('slip') ) { $did_something++; $descendant->set_att('_TYPE' => 'produce'); # Move the out of the section # # This appears to be the problem, even though # this should never be reached in the second # document (no descendants) $descendant->move('before', $_[1]); } $_[1]->delete; $_[0]->flush() if $did_something; 1; }