use warnings; use strict; use XML::Twig; my $xmlstr = < emcon *sppcon* CDOPS cpemcon * COPS dbemcon * COPS tuxemcon * COPS EOF my $twig = XML::Twig->new( twig_handlers => {ACCOUNT => \&acct} ); $twig->parse($xmlstr); sub acct { my ($t, $elt) = @_; print $elt->att('id'), "\n"; print $elt->first_child('USERNAME' )->text(), "\n"; print $elt->first_child('HOST' )->text(), "\n"; print $elt->first_child('PERMISSION')->text(), "\n"; print "\n"; } __END__ 4cf031986c emcon *sppcon* CDOPS b92794bbd7 cpemcon * COPS 8ff0478641 dbemcon * COPS 22d2647740 tuxemcon * COPS #### sub acct { my ($t, $elt) = @_; print $elt->att('id'), "\n"; for my $tag (qw(USERNAME HOST PERMISSION)) { print $elt->field($tag), "\n"; } print "\n"; }