You could use DB_File to store every filename (with complete path) that you link to. This gives you a persistent hash that you can check against (if the path/file is not already in the hash, then you have never linked to it before, etc.) This should work fine unless you have more than millions of files to keep track of.