my $sabal = new XML::Twig( twig_roots => { 'foo/yahoo' => #'bayking[@id="kingtony"]' => sub { my ($yabal, $element ) = @_; if ( $element->first_child('bayking_list')->first_child('bayking')->att('id') eq 'kingtony' ) { $element->print; } } } ); $sabal->parse($xml);