+----------------------------- In the scalar $s (interpreted as a string), | +--------------------- if you find an _ (underscore) | | +----------------- that's followed by 0 or more of anything but an _ (underscore) | | | and then the end-of-string, | | | + -- replace it with a , (comma). | | | | V V V V $s =~ s{ _ (?= [^_]* \z) }{,}xms;