This is one way that use Perl tricksmain internals, without the need to use our global variable:
rename -n 'BEGIN{$main::i = 28} s/_.*/sprintf("_%03d.png", $main::i++)/e' ./*.png The tricksolution here is to use the fully-qualified scalar variable $main::i (same as when in package main).
This is a tricksomething to have in the toolchest.