my @temp; for my $h (@hosts) { if ($h =~ m/^\d{2}\z/) { push @temp, map "$_.area$h", @shorts; } else { push @temp, $h; } } @hosts = @temp;