in reply to Efficient hash storage?

Updating the hash (rare) does the reverse using:
$val=join(',',(keys(%hash)))

No it doesn't. Your original $var contains key-value pairs, whereas the code for the reverse you show contains values only. To get the reverse, you need something like:

$val = join(',', %hash);

Paul