THE PROBLEM Extract the XML string from a text file formatted like this: -------------------------------------------------------------------------------- 0000000020: 3c3f786d 6c207665 7273696f 6e3d2231 2e30223f '..997<' -------------------------------------------------------------------------------- THE SOLUTION -------------------------------------------------------------------------------- #!/usr/bin/perl use strict; open H, shift || 'filename.txt' or die "Error: $!\n"; print pack "(H*)*", map{s/^\d+:| |'.+?'\n?$//g && $_}; --------------------------------------------------------------------------------