my $attempts; while (not rename $file1, $file2) { $attempts++; die "Could not rename file: $!" if $attempts > 7; sleep $attempts; }