use strict; use warnings; use String::Random; my $oldfile = 'picture.jpg'; my $random = String::Random->new; if ($oldfile =~ /\.jpg$/) { my $oldname = $oldfile =~ s/\.jpg$//r; my $newfile = $random->randpattern('.' x length $oldname) . '.jpg'; print "$oldfile will be renamed $newfile\n"; }