use strict; use warnings; { my ($input_file) = @ARGV; open XML, $input_file or die; my $xml_data; ##Read the XML into xml_data while (my $line = ){ $xml_data .= $line; } ##Parse xml_data while ($xml_data =~ /(.*?)<\/Dataentry>/s){ ##Keep xml block to print if needed my $xml_block_to_print = $1; my $xml_block_to_parse = $xml_block_to_print; $xml_data = $'; ##Parse the xml block, and if we have a match, print! while ($xml_block_to_parse =~ /(.*?)<\/Data>/){ my $data = $1; $xml_block_to_parse = $'; if ($data eq 'bbbbbb'){ print "$xml_block_to_print\n"; last; } } } }