perl -wle "$x='000'; $x++ and $o=$_ and s[/(.*$)][/$x-$1] and rename($o,$_) or warn $! for glob qq[$ARGV[0]/*]" dir