It seems like you are doing event driven programming. There
are various modules on CPAN that deal with event driven
programming, each with their advantages and disadvantages.
To name a few: Tk, POE, and Event. There's also Uri's pet
project, stem, but I don't think that's on CPAN.
Abigail