use strict; use warnings; use XML::Twig; my $xml = < #### Key338478082620114.285714285714 Reconcile3017780622-70Insufficient Information Training338477654-0Non-Billable Management301777893-0Non-Billable Break337933843-0Non-Billable Excess overload3379775701416.66666666666667 Management312388898-0Non-Billable Management312322304-0Insufficient Information Management312311121-0Non-Billable Adapt31237814308-0Insufficient Information Import341776584App K411.4285714285714 Break312322732-050.65687 key31237814308045.5544 Supervision319254281-0Non-Billable #### XML my $t= XML::Twig->new (twig_roots => {emp => \&emp, prod => \&prod}); my %emp; my $currEmp; $t->parse ($xml); print "$_ - $emp{$_}\n" for sort keys %emp; sub emp { my ($t, $data) = @_; $currEmp = $data->trimmed_text (); $emp{$currEmp} ||= ''; } sub prod { my ($t, $data) = @_; my $text = $data->trimmed_text (); return if $text !~ /^\d+(\.\d*)?/; $emp{$currEmp} ||= 0; $emp{$currEmp} += $text; } #### 3017 - 3123 - 96.21127 3192 - 3379 - 6.66666666666667 3384 - 114.285714285714 3417 - 11.4285714285714