in reply to undef number?

This number I have to check each time (until the loop finishes) if it has the highest value (max value).

Don't you have a maximum value in mind?    If you want it to hold the maximum value that Perl defines for a number then how do you expect $number_to_compare to ever be greater than it?