in reply to Re^2: IF condition with a range
in thread IF condition with a range

You could also use

if (abs($y-$x) <= 1)

(Added to earlier post)