if ($pingObj->ping($IpAddress, 1)){ my $MachineName = uc(gethostbyaddr (inet_aton($IpAddress), AF_INET)) or "[FAILED]"; $MachineName = ($MachineName =~ /^(.*?)(-UDP\w*)?\./i)[0]; print "$IpAddress\t$MachineName" if $VERBOSE; } else { print "$IpAddress\tNo Response\n" if $VERBOSE; } #### # Assuming you won't have a machine named "0" $MachineName = ($MachineName =~ /^(.*?)(-UDP\w*)?\./i)[0] || ($IpAddress . '[NULL]');