This is option Stock 3 of 1 #### 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 #### sub del{ my $filename="test.txt"; my $template_data = "new/".$filename; undef $/; # Slurp mode open(DATA_IN, "$template_data") || print "Can't open output file1: $template_data\n"; #binmode DATA_IN; $_ = ; while(/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->/sg){ $a=$1;$b=$2;$c=$3;$d=$4;$e=$5; if ($a eq $location){ if($b eq $obj_name) { $c=$page; $_=~s/<\?--([^-]*)-([^-]*)-->(.*?)<\/\?--([^-]*)-([^-]*)-->//sg; } } $list=$list. "$c\n";} close DATA_IN; open( DATA_OUT, ">new/test.txt" ) or die "$!\n"; print DATA_OUT "$list\n"; close DATA_OUT;