sub bracket { local $_ = @_ ? $_[0] : $_; return "[ $_ ]"; } sub quote { local $_ = @_ ? $_[0] : $_; s/(["\\])/\\$1/g; return qq{"$_"}; } @{$_[0]->{'images'}{'section_a'}} = ( [ "image1.gif" , "mark('a',1)" ], [ "image2.gif" , "mark('a',2)" ], ); print( bracket # Put brackets around the row. join ',', # Join the records. map { # For each record, bracket # Put brackets around each record. join ',', # Join the fields. map quote, @$_ # Quote and escape the fields. } @{$_[0]->{'images'}{'section_a'}} ); __END__ output ====== [ [ "image1.gif","mark('a',1)" ],[ "image2.gif","mark('a',2)" ] ]