use Getopt::Long; GetOptions( 'infile|i=s' => \$opt_infile, ); if (defined $opt_infile) { $file{in} = $opt_infile; (@targets = $file{in}); } foreach my $nonsane(@targets) { chomp $nonsane; unless ($nonsane =~ (/^(\w|-|\.)+$/)) { print " Ack - $nonsane is an improperly formatted device name.\n"; print " Only alphanumeric, underscore, dash and dot allowed.\n"; exit; } } print (" Specified target names all valid.\n");