perl -e 'foreach $index (reverse( 5..9 ), 12..18) { print "$index\n" }' #update: or perl -e 'print "$_\n" for reverse( 5..9 ), 12..18'