while ( my ($nbname, $ip) = $sth->fetchrow ) { if ($ip) { print "DB has IP=$ip for nbname=$nbname.\n"; } else { print "DB has no IP value for nbname=$nbname.\n"; if ($data{$nbname}{'IP'}) { print "... but CSV file has value: $data{$nbname}{'IP'}.\n"; } } }