in reply to Need regular expression

The flip-flop operator can help:

use strict; use warnings; while(<DATA>){ next if m|^/\*.*\*/|; print if /^OT;$/../^RT;$/; } __DATA__ 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;