in reply to Detecting if a scalar has a number or string

According to the perlfunc manpage on sort, I should be able to use <=> to compare things, and if it's NaN, it turns out undefined. I think the page is outdated. The following turns out true in ActiveState Perl Build 810 (Perl 5.8.4):

$a = 'string'; if (defined ($a <=> $a)) { print "Oops"; }

The == operator also seems to work for NaNs (Not-a-Numbers) when it's not supposed to.

I think you are under a misapprehension. $a there is not a NaN; a NaN is a floating point value that doesn't correspond to an actual number. On systems that support NaNs and infinite numbers, there are various rules about when a math operation will return one of these types. Try:
my $Inf = 9**9**9; my $NaN = sin($Inf); print "inf is: $Inf\n", "NaN is: $NaN\n";
Note: these are not strings; setting $a = "Inf" is not the same as setting it to an Inf floating point value.