$ perl -E ' > $_ = q{(1,2,3) xxx (1,2,3)}; > s{([^(]+)(?=\)$)}{ join q{,}, map qq{\x27$_\x27}, split m{,}, $1 }e; > say;' (1,2,3) xxx ('1','2','3') $