sub getHostname { my ($IpAddress) = @_; unless ($pingObj->ping($IpAddress, 1)) { print "No response from $IpAddress\n" if $VERBOSE; return; } # Do the rest of the stuff here } #### # This is the rest of the stuff. # Note the use of single quotes. It's not a performance thing - it's a # readability thing. Double-quotes are for interpolation. Single-quotes # tell the reader there's no interpolation here. my $Host = uc(gethostbyaddr (inet_aton($IpAddress), AF_INET)) or '[FAILED]'; # Get rid of everything starting with -UDP. # In your version, you captured everything before -UDP. Same difference. $Host =~ s/-UDP.*//; $Host = "${IpAddress}[NULL]" if $Host eq ''; print "$IpAddress\t$Host\n" if $VERBOSE; return $Host; }