sub equals { my ($val1, $val2) = @_; # first test for undef-ness if ( ! defined $val1 || ! defined $val2 ) { return 1 if (! defined $val1 && ! defined $val2 ); return undef; #case one is undef, other is def } # have to do next line this because strings evaluate to 0 in == context ... if ( ! $val1 && ! $val2 ) { # then test for ""-ness return 1 if ( ($val1 eq "") && ($val2 eq "") ); return undef if ( $val1 eq "" || $val1 eq "" ); #case one is "" other is 0 # then test for 0-ness return 1 if ( ($val1 == 0) && ($val2 == 0) ); } # then test for equality using 'eq' return 1 if ( $val1 eq $val2 ); # then test for equality using '==' if ( int($val1) && int($val2) ) { # all other number cases are already covered by # above tests (eg. both 0, or both the same string) # this merely takes care of cases like: # 1000.0000 == 1000 return 1 if ( $val1 == $val2 ); } # couldn't find any, so i guess they are not equal return undef; }