$str =~ s/((?:(?!\").)*)(\"[^\"]+\")((?:(?!\").)*)/ my $fi = $1;my $se = $2; my $th = $3; $fi =~ s| |\,|g;$th =~ s| |\,|g; "$fi$se$th"/egs;