my $f = $file_in; while (-e $f) { $f = "$file_in." . int(rand(100000)); } rename($file_in, $f);