use warnings; use strict; use Regexp::Common qw/comment/; my $sample = <<'END_SAMPLE'; Hello // World a /* test */ b xyz /* asdf qwertz /* uiop */ ijk END_SAMPLE $sample =~ s/$RE{comment}{JavaScript}//g; print $sample; __END__ Hello a b xyz ijk