use strict; use warnings; my $state; my $firstAttempt = 1; while (1) { if($firstAttempt) { $state = promptUser("What network to listen for SNMP traps [hsbn or admin]? ", "admin"); ; $firstAttempt = 0; } else { $state = lc promptUser("ERROR: $state Invalid Re-enter the network"); } if (0 == index 'hsbn', $state) { $state = 'hsbn'; last; } elsif (0 == index 'admin', $state) { $state = 'admin'; last; } } if ($state eq 'hsbn') { #some action }