use XML::Twig ; XML::Twig->new( twig_handlers => { '*' => sub { print $_->xpath, "\n"; }, }, )->xparse( "somefile.xml" );