#!/usr/bin/perl use strict; use warnings; use XML::Twig; $|++; open my $fh,'<','xmlstream.xml' or die; while () { chomp; if ($_ =~/Content-Length: (\d+)/){ my $len = $1; my $xml; my $read = read (DATA,$xml,$len,0); print "read: tried $len got $read: [$xml]\n"; my $t= XML::Twig->new( pretty_print => 'indented', twig_handlers => { 'ipAddress'=>sub{print "\t\tIP ADDRESS:\t",$_[1]->text,"\n"; } } ); $t->parse($xml); } } __DATA__ Content-Type: application/xml; charset="UTF-8" Content-Length: 478 10.1.10.23 80 HTTP c4:2f:90:00:00:00 1 2015-06-24T19:37:22--8:00 0 videoloss inactive videoloss alarm Content-Type: application/xml; charset="UTF-8" Content-Length: 514 10.1.10.23 80 HTTP c4:2f:90:00:00:00 1 2015-06-24T19:37:22--8:00 1 VMD active Motion alarm