./myscript.pl -h peanut 01 13 44 18 27 #### #!/usr/bin/perl -w use warnings; use strict; # Will be set by getopt(). my %opt = ( 'h' => 'peanut,cashew'); # Contains only shorthand subdomains for now, but items will be # expanded to full hostnames. my @hosts = ( '01', '13', '09'); # The short hostnames to target in each subdomain. my @shorts = (split /,|\s+/, $opt{'h'}); for my $h (@hosts) { if ($h =~ m/^(\d{2})$/) { for my $short (@shorts) { push @hosts, "$short.area$h"; } } } @hosts = grep {!/^\d{2}$/} @hosts; print join(' ', @hosts) . "\n";