my $ele = $root->look_down( _decl => ...was specified..., ) or die qq{declaration not found\n}; my $dec = $ele->attr('_decl'); #### my $ele = $root->look_down( sub { $_[0]->attr('_decl') } ) or die qq{declaration not found\n}; my $dec = $ele->attr('_decl'); #### my $dec = $root->attr('_decl') or die qq{declaration not found\n}; #### $dec->attr(text => 'DOCTYPE html PUBLIC "HTML4"'); #### $root->attr('_decl', HTML::Element->new('~declaration', text => 'DOCTYPE html PUBLIC "HTML4"', ) ); #### #!/usr/bin/perl use warnings; use strict; use HTML::TreeBuilder; my $content = do{local $/;}; my $root = HTML::TreeBuilder->new_from_content($content); $root->attr('_decl', HTML::Element->new('~declaration', text => 'DOCTYPE html PUBLIC "HTML4"', ) ); print $root->as_HTML; __DATA__ declaration

declaration

##
## declaration

declaration