*the substring can conatin commas in it*
Sorry, this doesn't make sense to me. If the input string is `"1,2,3,4,5,6,7"`, then does `$a` get `"1,2"`, or does `$b` get `"2,3"`, and so on...
Or is this CSV, as swl correctly pointed out? Then you should use Text::CSV.
If not, then as I said, please provide lots of examples of valid input with the expected output, as well as lots of examples of invalid input.
| [reply] [d/l] [select] |

"a ,b,c,d,e" is okay (space with substring) but one space or more (without any symbols) isn't valid. For example: "a, ,c,d,e" or "a,b,c, d,e" are not valid.
| [reply] |

Ok I understand, forget about commas in the substrings.
your regex is good and its what I need except it doesn't handle an empty space case: "a,b,c, d,e" (bad case).
how can I add it to the regex?
| [reply] |

Again, more examples please. Only literal spaces? I am guessing you mean one *or more* spaces? What about other whitespace? Is `" x ,..."` valid? Is `" x y ,..."`? What is the expected output for those cases? And so on.
| [reply] [d/l] [select] |

Comment onRe^2: check if string is valid with special cases