my $photo = $CGI->param("pic") my $copydir = 'img'; my ($file_extension) = $photo =~ /([^.]+)$/; #get photo extension my $newf = "011190.$file_extension"; #rename photo to its extension to keep the original resolutions of the file rename($photo, $newf); $upload = $CGI->upload("pic"); open ( UPLOADFILE, ">$copydir/$newf"); close UPLOADFILE;