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