use warnings; use strict; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { town => \&town }, ); $twig->parsefile('datafile_towns.xml'); sub town { my ($twig, $town) = @_; if ($town->first_child('location')->first_child_text('mapx') > 300) { print $town->first_child('towndata')->first_child_text('townname'); print "\n"; } } __END__ sometown