#!/usr/bin/perl #get start and end comment my $start = $ARGV[0]; my $end = $ARGV[1] || "\n"; open(FILE, "test.txt") || die; { local $/ = undef; #set to 'slurp' mode $_ = ; #read entire file into $_ } close FILE; # #print all comments that are matched in file # while( /\Q$start\E(.*?)\Q$end\E/sg ) { print $&, "\n"; } #### blah blah blah blah blah *** multi line comment **!! blah blah blah blah blah blah blah blah blah blah blah *** inline comment **!! blah blah /* c comment 1 */ blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah /* * c comment 2 */ blah blah // c++ comment 1 blah blah // c++ comment 2 #### prompt$ regex.pl '***' '**!!' *** multi line comment **!! *** inline comment **!! prompt$ regex.pl '/*' '*/' /* c comment 1 */ /* * c comment 2 */ prompt$ regex.pl '//' // c++ comment 1 // c++ comment 2