use constant END_TAG = qr##; my $xml = ""; while () { my $line = $_; $xml .= $line; if ($line =~ END_TAG) { # Process the XML here... # Start again $xml = ""; } }