I really would like to know why you want to do this.
I believe that Data::Dumper and FreezeThaw will
take care of serializing data for you, in a much more
secure way. Take a look at the internals of those
modules if you are searching for the "how does it work"
knowledge.