#! /usr/bin/perl -w use 5.018; my $string = "OT; some line /*asas*/ # here C-style comments should be removed /*asdas*/ #OT;.....RT;should be replaced with OT;.....DT;OT.......RT; *note1 some line RT; some lines somlelines OT; another line /*asas*/ /*asdas*/ yet another line RT;"; =head first, my note: # /me does not understand WTF the OP's comment above means and now, OP's spec: 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; =cut my $regex1 = qr([/][*]); my $regex2 = qr([*][/]); $string =~ s/$regex1.+?$regex2//gs; say $string; =head output C:\> junk_check.pl OT; some line # here C-style comments should be removed #OT;.....RT;should be replaced with OT;.....DT;OT.......RT; *note1 some line RT; some lines somlelines OT; another line yet another line RT; C:\> =cut