my $file = shift || (print "NOTE: \tYou didn't provide the name of the file to be checked.\n" and exit); 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); sub parsing { my ( $twig, $accounts ) = @_; my %hash = @_; my $ref = \%hash; #because was getting an error of Odd number of hash elements return $ref; $twig -> purge; }