in reply to unlink unworking

> $theLink doesn't change at all at
> any point in the code

Either it does, or you may have mis-typed the variable name (e.g. $TheLink). The use strict should help ferret the latter out, and btrott's suggestion should show the former.