use Net::Whois::IP ('whoisip_query'); # This module is not installed automatically with a # Perl installation, so you'll need to install it # from CPAN in order to be able to use its # whois_ip_query function. use Fcntl (':flock'); if ($userIP) { my $location_of_some_log_file = '/var/logs/my_log_file.log'; open ( my $log_fh, '>> :encoding(UTF-8)', $location_of_some_log_file ) or die "FATAL: Trouble opening '$location_of_some_log_file' for appending: $!"; flock ( $log_fh, LOCK_EX ); my $ip_whois_response = whoisip_query($userIP); if ($ip_whois_response) { print {$log_fh} "Running whois on IP address '", $userIP, "':\n\n"; foreach ( sort keys( %{$ip_whois_response} ) ) { print {$log_fh} "$_ $ip_whois_response->{$_} \n"; } } else { print {$log_fh} qq|Cannot run whois to do an IP lookup, because no response received when invoking whoisip_query method of Perl module Net::Whois::IP on IP '$userIP'\n\n|; } close $log_fh or warn "WARNING: Some trouble closing file handle for '$location_of_some_log_file': $!"; }