#!/usr/bin/perl -w use warnings; use strict; use XML::Twig; my $xml = <This is an id Title stuff Another title XML my $twig = XML::Twig->new( twig_roots => { ID => \&dump, TimeStamp => \&dump, IP_Address => \&dump, Title => \&dump, Complainant => \&dump, } ); $twig->parse($xml); sub dump { my ($t, $elt) = @_; (my $text = $elt->text()) =~ s/^\s+|\s+$//g; print "$text\n"; }