use strict; use warnings; use XML::LibXML qw( ); my $xml = <<'__EOI__'; __EOI__ my $doc = XML::LibXML->new()->parse_string($xml); my $root = $doc->documentElement(); for my $node ($root->findnodes('//cat[not(@meow)]')) { $node->setAttribute(meow => 'default'); } print $doc->toString(); ####