use strict; my $DB; my @DB = qw(DB1 DB2); { $DB = select_db(); redo unless grep {$_ eq $DB} (@DB,'Q'); } die if $DB eq 'Q'; sub select_db { print "Select a database: "; chomp($_ = ); return $_; }