use strict; use warnings; my $location = "1"; my $obj_name = "Stock3of1"; { local $/ = "\n\n"; while ( ) { if ( /<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/s ) { print unless ( $location eq $1 and $obj_name eq $2); } } } __DATA__ This is option News 1 of 1 This is option Weather 2 of 1 This is option Stock 3 of 1 Option Second 1 of 2 Option Third 1 of 3