foreach my $key (keys %data) { print "key=$key, value=$data{$key}\n"; $data{$key} =~ s/(^|$)/"/g if $data{$key} =~ /,/; }