... while($in){ if($in =~ /exit/i){ last; } } # Code will continue here ...