sub to_literal { "'$_[0]'" } my $x; for (...) { if (!$x) { $x = to_literal($_); } else { $x = join(', ', to_literal($_)); } } my @a = eval $x;