You could use Tie::Scalar to make sure that a var $x will always stay an integer, by declaring STORE. But that will slow down every operation on $x.