What you want to do is save "state" from one invocation of your CGI to the other. There are several ways to do this, with different pros and cons...
Merlyn has an excellent node on this called
Adding "state" to HTTP. Read and enjoy...
Gary Blackburn
Trained Killer