#!/bin/perl -w use strict; undef $/; # so will slurp the entire file my $string=; $string=~ s{/\*.*?\*/}{}gsx; # do not forget the s modifier so . matches \n too print $string; __DATA__ A text /* with comments */, some even /* cross several lines */, some even /* cross many, many, many */ lines