in reply to Re^2: adding 1 to a char of 1
in thread adding 1 to a char of 1

Use substr to extract and replace:

my $oldfile = "name_0009"; my $num = substr($oldfile, -4); ++$num; my $newfile = substr($oldfile, 0, -4) . $num;

Or use the lvalue form to simplify things:

my $oldfile = 'name_0009'; substr(my $newfile = $oldfile, -4)++;