you can do this in awk with the single line statement:
awk '{sum += $3-$2}END{printf "total size: %d\n",sum}' file.bed