for my $zone (@zones) { my $lookup = `nslookup $zone $ns1`; my ($ip) = $lookup =~ /^Address:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/im; print $ip if defined $ip; }