## When we are looking on REGEXP for something that is after other, ## genreally "\n", we forget about the beggin of the string, ## that enables an occurrence that is not after "\n". ## Soo, to do this in only one REGEXP we use (?:^|\n) ## remove comments: $str =~ s/(?:^|\n)[ \t]*#//gs #### $str =~ s/^[ \t]*#.*\n//gm;