What about this simple method?
- remove all substrings between double or single quotes first
- extract out substring after a
#
by a simple regular expression cpature
Here is the test program for your sample input:
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
chomp;
s/['"][^'"]*['"]//g;
if (m/#(.*)/) {
print "$1\n";
}
}
__DATA__
"#dummy comment" asd asd
' abc # dummy comment'
abc #real comment