in reply to DNS problems with Mail::SPF
my $ip = $mail->header("X-IP");
Did you check if $ip has a reasonable value(the sender's IP address)?
As far as I know, header names starting with "X-" are non-standard, so they may exist but they do not necessarily. I'd bet that an empty string is causing you the trouble.