I looked at your
previous post, but you didn't mention
why you were unable to use
any CPAN modules for this project.
Since that is rarely the case, understanding your reasons might help someone help you.
Update: One way of "using" a module would be to read the source to see how the module author accomplished the task, or (depending on the license) copying the entire module source into your own program.
(I am constantly amazed at policies that consider untested "roll-your-own" solutions to be more secure than solutions that have experienced at least
some level of peer review. And I'm sorry I couldn't do more to address your problem directly.)
Impossible Robot