The following perl script will strip // and # style comments from a file, and print the remaining file. It takes one command line argument, the path of the input file.

#!/usr/bin/perl
use strict;
use warnings;
my $file=$ARGV[0];
open (IN,$file) or die "Couldn't open: $!";;
while (my $line = <IN>) {
    #Remove # style comments
    if ($line =~ /^\s*#/) { next; }
    #Remove // style comments
    if ($line =~ /^\s*\/\//) { next; }
    print $line;
}

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.