XML::Twig->new()->parsefile('my xml file'); #### my $twig = XML::Twig->new()->parsefile('my xml file'); # Use XPath-like expressions to find the nodes you want. my @nodes = $twig->get_xpath('attribclass/attribdef[@name="mtl_Kdiff'); for my $node (@nodes) { # Process... # Example: $node->set_att('synthetic', 'false'); } # Or navigate through references. my @attribdefs = $twig->root->first_child('attribclass')->children('attribdef'); for my $node (@attribdefs) { # Process... } #### my $twig = XML::Twig->new( twig_handlers => { 'attribdef' => sub { my ($twig, $elt) = @_; if ($elt->att('name') eq 'mtl_param') { # Do something. } elsif (...) { } # etc. $twig->flush; } } )->parsefile('my xml file'); $twig->flush; #### my $hash = XML::Twig->new()->parsefile('my xml file')->simplify(); use Data::Dumper; print Dumper($hash);