in reply to CGI coding style

While this may not be directly applicable to your situation, you may want to try some sort of "finite state machine". (Purists may say this is not a true fsm . . . )
$state = 'initial_state'; while ($state ne 'completed') { if ($state eq 'state1') { #do something $nextstate = 'another state'; } if ($state eq 'state2') { # and so on } $state = $nextstate; # so we don't confuse our logic }
Sure, it is not oo in style, but it can be easier to maintain.