use CGI::Fast qw(:standard); while ($query = new CGI::Fast) { # Do stuff exit if $exit_flag == 0; }