Are you sure you want to save this information in cookies? If you really care about this data, it's probably better not to save it in a cookie since any user can blow their cookies away at any time. If you don't really care about this data, then perhaps it's not really worth saving at all.
However, if you really want to do it, and you're doing it via CGI, look at CGI.pm, specifically the stuff on HTTP cookies.