#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t= XML::Twig->new( # the twig will include just the root and selected titles twig_roots => { 'product' => \&print_elt_text } ); $t->parsefile( './workingfiles/eur/eurfeed.xml'); sub print_elt_text { my( $t, $elt)= @_; my $prodcode = $elt->first_child( 'STOCK_CODE')->text; my $wholesale_price = $elt->first_child( 'WHOLESALE_PRICE')->text; my $map = $elt->first_child( 'MAP_Price')->text; my $disc = $elt->first_child( 'DISC')->text; print "Product ID: " . $prodcode . "\n"; print "Wholesale Price: " . $wholesale_price . "\n"; print "MAP: " . $map . "\n"; print "Disconnected: " . $disc . "\n\n"; $t->purge; # frees the memory }