my $valid = 0; my $state; my $firstAttempt = 1; while(!$valid){ if($firstAttempt) { $state = promptUser("What network to listen for SNMP traps [hsbn or admin]? ", "admin"); ; $firstAttempt = 0; } else { $state = promptUser("ERROR:$state Invalid Re-enter the network"); } if($state =~ /hsbn|admin/) { $valid = 1; } } if ($state =~ /hsbn/i) { //some action }