my $fmt = '%.02f'; if ( sprintf($fmt, $num1) eq sprintf($fmt, $num2) ) { print "they're the same, to two decimal places\n"; }