use warnings; use strict; use XML::Twig; my $file = './test.xml'; my $twig = XML::Twig->new(); $twig->parsefile($file); my $root = $twig->root; foreach my $item ($root->children('Main')){ print $item->att('id').", ".$item->att('name'); print "\n"; }