in reply to Calculate the overlap length between two ranges
Or maybe get some inspiration from Set::IntSpan