parse_xml( $xmlfile); sub parse_xml { my( $file)= @_; my $ups_able_info= []; my $twig1 = XML::Twig->new( twig_handlers => { 'ups:TABLE_INFO/ups:field' => sub { parse_table_info( @_, $ups_able_info); } ) ->parsefile( $file); # now $ups_table_info is filled } sub parse_table_info { my( $twig, $table_info, $ups_able_info)= @_; # note the extra argument my $table_column = {}; $table_column->{$table_info->field('ups:tag')} = $table_info->field('ups:ui_name'); push(@{$ups_table_info}, $table_column); }