#!/usr/bin/perl use strict; use warnings; use XML::Parser; my $current_element = my $current_amount = ""; my $p = XML::Parser->new( Handlers => { Start => \&handle_start, Char => \&handle_text, End => \&handle_end } ); $p->parsefile( "org1.xml" ); sub handle_start { my ( $xp, $element, %attr ) = @_; $current_element = $element; # keep track of where we are } sub handle_end { my ( $xp, $element ) = @_; if ( $element eq 'Amount' ) { # did we just close an "Amount" tag? print "$current_amount\n"; $current_amount = ""; } $current_element = ""; } sub handle_text { my ( $xp, $string ) = @_; # do stuff here depending on where we are now: $current_amount .= $string if ( $current_element eq 'Amount' ); }