in reply to Renaming an image file

You want executable code, so you need to use /e.
s/^([^_]+_).*(\.\w{3})\z/$1 . sprintf("%08d", rand(100000000)) . $2/eg +;
or
s/^([^_]+_).*(?=\.\w{3}\z)/$1 . sprintf("%08d", rand(100000000))/eg;
or (5.10 required)
s/^[^_]+_\K.*(?=\.\w{3}\z)/sprintf("%08d", rand(100000000))/eg;

This way the files will be unique and uniform for my storage needs.

Random numbers aren't unique. They're random.