#!/usr/bin/perl -w use strict; die "Usage: ", $0 =~ /([^\/]+)$/, " \n" unless @ARGV && $ARGV[0] =~ /^\d+$/; my ($c, @list); for (reverse split //, $ARGV[0]){ unshift @list, $c++ % 3 || $c == 1 ? $_ : "$_,"; } print @list; # Or, instead of "cheating" with an unquoted list, we could # aggregate to a string. It's not quite as neat, though. :( # # my ($c, $out); # for (reverse split //, $ARGV[0]){ # $out = $c++ % 3 || $c == 1 ? "$_$out" : "$_,$out"; # } # print "$out\n";