OT; some line /*asas*/ ##here comments should be removed /*asdas*/ #OT;.....RT;should be replaced with OT;.....DT;OT.......RT; some line RT; some lines somlelines OT; some line /*asas*/ /*asdas*/ some line RT; what i need is like OT; some line1 some line2 DT; OT; some line1 some line2 RT; some lines3 somlelines4 OT; some line5 some line6 DT: OT; some line5 some line6 RT; if($string=$string=~ s/OT;(.*?)(/*(.*?)*/)*(.*?)RT;/OT;$1$4DT;\nOT;$1$4RT;/gsr) { print "modified string".$string; }