$location = "1"; # hard code deletion info $obj_name = "Stock3of1"; undef $/; # Slurp mode $_ = ; print "-Before=====================================\n"; print "$_\n"; while(/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/sg){ $a=$1; $b=$2; $c=$3; $d=$4; $e=$5; # debug output # print "-A--------\n$a\n-B--------\n$b\n-C--------\n$c\n-D--------\n$d\n-E--------\n$e\n-eor------\n\n"; unless (($a eq $location) and ($b eq $obj_name)) { $list=$list. "$c\n"; } } print "-After======================================\n"; print "$list\n"; __END__ 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 #### -Before====================================== 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 #### -After====================================== This is option News 1 of 1 This is option Weather 2 of 1 Option Second 1 of 2 Option Third 1 of 3