perl -e '@array = qw (hello world 1 2 3); @req = qw (2 3 4); $str = print join (",",@array[@req]), $/;' __END__ 1,2,3