The regex to match quoted strings is discussed in detail in Jeffrey Friedl's excellent book: Mastering Regular Expressions. The regex to do this (and many more) is also available in the superb Regexp::Common CPAN module.
Modifying ambrus's solution with Friedl's optimized regex to match a quoted string (which also allows for escaped characters) gives:
s/("[^"\\]*(?:\\.[^"\\]*)*")/($x=$1)=~y: :_:, $x/ge;
In reply to Re^2: regexp - replace spaces in quoted string
by eyepopslikeamosquito
in thread regexp - replace spaces in quoted string
by /dev/luser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |