leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:

I parse string using /gc and \G regexes. Current solution for skipping white characters and comments starting from # to the end of line is:

$$a =~ /\G(?=(\s|#))(?:\s++|#.*+)++/gc;

Look ahead ?= assertion is necessary, because zero-length matches cause problems. That solution unfortunatelly gives error:

Complex regular subexpression recursion limit (32766) exceeded

I have changes to such one:

while ($$a =~ /\G(?:\s++|#.*+)/gc) {};

but this is not elegant. I have changed "+" to "*" after "\s" and this also solves the problem, but I don't know why...

$$a =~ /\G(?=(\s|#))(?:\s*+|#.*+)++/gc;

Questions: (1) what is the better solution to strip white chars and commments (2) why * instead of + solves the problem?