in reply to Quoting each word in an arrayref

This returns "key":"val1, val2" but I need each word to be quoted like this "key":"val1", "val2".

Aside from the fact that your intention is to produce JSON output, so using a JSON module would be the best solution, your question also brings up a more general problem: quoting items in a list.

A possibly helpful module for this might be Text::CSV

Also, you can do it with join as you attempted.

In your join, you only specified the comma and space:

join(', ', @list)

What you left out was including the quotes. There is a bit of a trick as join only puts the supplied string between list members, so you need to provide the first and last quotes yourself.

'"' . join('", "', @list) . '"'