in reply to increment a hex number

I have some hex numbers like 0x000000 0x010000 0x020000 0x030000 . . .

You don't have hex "numbers", you have strings that represent numbers!
To increment (or decrement) a number represented by a string, you have to convert that string to a number.

Perl is designed to do this very easily in base 10!
For example, $x="000032";
If you print $x, you will get "000032" (a string).
BUT, if you write: $x +=0; print $x; #you will get 32 not 000032 because Perl converts the string to a number and then adds "0" and you just get 32, not "0000032". I suspect this maneuver to "delete leading zero'es" is in the Perl FAQ somwhere. I've never seen it, but this is how it works. Try it!

Perl is magic, but it is not super magic. If you want to convert a hex string into a number, you have to help Perl out a bit by using the hex() function. So this is slightly more difficult than converting a decimal string to a number.

my @formatted_nums = ( '0x000000', '0x010000', '0x020000', '0x030000', ); foreach my $num (@formatted_nums) { $num = hex($num); #converts all hex strings to numbers } foreach my $num (@formatted_nums) { print "$num\n"; #see now decimal numbers... } # prints: # 0 # 65536 # 131072 # 196608 foreach $num (@formatted_nums) { printf "%X\n", ++$num; #print hex value of the number +1 } #prints: 1 10001 20001 30001