in reply to Calculate the overlap length between two ranges

"the length between some overlapping numerical ranges"
31-52 and 27-50 is it 27 - 52 which is 25 or 31 - 50 which is 19 ?
the task is not clear anyway:
$a = '31-52 27-50'; @a = sort split /\s|-/, $a; print $a[3] - $a[0]," or ",$a[2] - $a[1],"\n";