in reply to
Efficient partial deep cloning
Walking the data structure and finding the elements is one way to do it (can there be more than one such elt? Do you need to worry about cycles in the structure?).
But it seems to me that these data structures have meta-information which you aren't currently storing. If you want efficiency you should store that information rather than recalculate it via a search.
One way to do this would be to wrap accesses to the data structure so that when a logic var is added to it, it's position is remembered (perhaps in some kind of inside-out object attribute stash). I'd do it this way, with a class around the data structure (add a "addLogicVar" method) although you could use TIE I guess.