use Net::Nslookup; open(INFILE, 'os.txt') || die("cannot open file: ".$!); my @lines = ; my $switch; foreach $switch(@lines) { my @output = nslookup(host => $switch, server => 10.1.10.42, type => "A"); (my $name, my $ip) = (split /:/, $output[3]); print "$ip\n"; } close INFILE;