#!/usr/bin/perl use XML::LibXML; use XML::Element; use strict; use warnings; # produces the following error: # XML::LibXML::Node::addSibling() -- nNode is not a blessed SV reference ... my $html = XML::LibXML->load_xml( IO => *DATA{IO} ); foreach my $dd ($html->findnodes('//dd[*/*/a[@class="f"]]')) { if (my $f = $dd->find('./*/*/a[@class="f"]/@href')) { print qq(F=$f\n); my $cc = XML::Element->new('dd'); $cc->push_content('foo'); $dd->addSibling($cc); # this line fails } } print $html->toString,"\n"; exit(0); __DATA__