in reply to Changing the target of refs of unknown type

Scalar::Util (which I believe is standard in newer perls) provides a reftype function you could use here.

But please reconsider your design. You are performing action at a distance, which is rarely a good thing. Perhaps you can to use proxy objects in your code instead?

Update: another indication that something's wrong: $old and $new will have to have the same underlying Perl type. You *might* be able to do some magic with globs. In itself that would be a clever hack; but really this shows that the code calling the retargeting needs to know so much, you may as well add smarts into your constructors. (Ah yes, look into factories too, if you're not familiar with those.)