I don't think code: $self->{$keyname}{$keysubname}= $keyvalue; is the best way.
What's wrong with that method? Seems very straightforward to me. The only way I would consider using a function to be superior is if you were validating the keys or data in some way (which isn't in your posted code).
---
It's all fine and dandy until someone has to look at the code.