#!/usr/bin/perl use strict; use warnings; my $HOST='www.xx.yy'; my $host_log='hosts.log'; my $host_err='hosts.err'; open(my $lh,'>>',$host_log) or die("ERROR open $host_log ($!)\n"); open(my $eh,'>>',$host_err) or die("ERROR open $host_err ($!)\n"); my @nslookup=qx{nslookup $HOST}; if(@nslookup) { if($nslookup[-1]=~/\Qserver can't find/) { print $eh @nslookup; } else { print $lh @nslookup; } } else { print $eh "ERROR EXEC nslookup $HOST ($?)\n"; } close($eh); close($lh);