The problem with s/\s*#.*$//; is that you might start breaking scripts unexpectedly. Given this (contrived but not unlikely) code snippet
my @fred = (1, 2, 3, 4, 5);
my $lastSub = $#fred;
print qq{$lastSub\n};
running your substitution will result in
my @fred = (1, 2, 3, 4, 5);
my $lastSub = $
print qq{$lastSub\n};
Perhaps something like
s{(?<!\$)#.*$}{};
would be better but there may be other syntax where the hash is not the start of a comment that I haven't thought of.
Cheers, JohnGG
Update: Found another non-comment occurrence of the # character in the colour values in Tk programs, e.g.
-background => #101010,
so perhaps now
s{(?<!\$)#(?![0-9a-fA-F]{6}).*$}{};
|