$Mid = 123;
$csum=0;
$csum+=$_ foreach split //,$Mid;
$csum%=10;
print $csum;