See
File::Overwrite for an implementation of this. But it still suffers from all the problems already noted elsewhere in the thread. To do the job properly you'll need a filesystem-specific tool, and even then you're at the mercy of how the underlying disk decides to lay data out.