#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Data::Dumper; my $xml = do{ local $/; }; my @hosts; my $parser = XML::Twig->new( twig_handlers => { 'HOST' => \&hosts, }); $parser->parse($xml); print Dumper \@hosts; sub hosts { my ($twig,$host) = @_; my %hash = ( ip => $host->findvalue( 'IP' ), dns => $host->findvalue( 'DNS' ), comment => $host->findvalue( 'COMMENT/VALUE' ), ); push @hosts, \%hash; } __DATA__ 192.168.1.1 IP address dns-server.test.de Linux Testnetz 1 Ansprechpartner Herr Mustermann 2 Standort Testnetz