in reply to
Detect variable change?
You could achieve this with the Perl debugger. The trick is to get an interactive debugger session into your CGI script as you interact with it through a web page. I do this with Catalyst apps and it fires of a terminal on my system when the code encounters a "$DB::single=1;" line. I'm not sure exactly how to acheive this with a simple CGI script but this thread here Debugging CGI/PERL has some advice on that.
Once you have the debugger session you can monitor a variable by setting a watch expression (w NAME_OF_VARIABLE), which will be triggered whenever the value of the variable changes.