#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use XML::Twig; sub parsing { my ( $twig, $accounts ) = @_; my $horrible_hacky_hashref = $accounts -> simplify ( forcearray => 1, keyattr => [] ); print Dumper \$horrible_hacky_hashref; } my $twig = XML::Twig -> new ( twig_roots => { 'Account' => \&parsing } ); #'twig_roots' mode builds only the required sub-trees from the document while ignoring everything outside that twig. $twig -> parsefile ($file);