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