#!/usr/local/bin/perl use strict; use warnings; my $data = 'Sending 104 bytes *** POST /path HTTP/1.0^M Content-type: text/xml^M Content-length: 37^M ^M SENT 104 HEADER HTTP/1.1 401 Unauthorised^M Connection: Close^M Content-Length: 0^M ^M '; #(Update) more like the output you requested print "Last Value=> "; while(){ (my $text = ($data=~ /(<\?.*\?>)/gi))? print qq('$1'\n) : exit; } #OUTPUT: #Last Value=> '' #''