#!perl use strict; my $qs =qr/'(?:[^']|\\')*'/; my $qqs=qr/"(?:[^"]|\\")*"/; my $ncs=qr<(?:[^'"/]|/[^/*])>; #' my $nocomment=qr/(?:$ncs|$qqs|$qs)*/; my $hit; while (<>) { # remove multiline /* comment if ($hit= s{^($nocomment)/\*(?:[^*]|\*[^/])*$}{$1}o ... s{^.*?\*/}{}) { redo if $hit=~ /E0/i; $_="\n" if $hit>1; print; next; } # remove one-line /*...*/ comment 1 while s{^($nocomment)/\*.*?\*/}{$1}o; # remove // comment s{^($nocomment)//.*}{$1}o; print; }