in reply to MD5 -- not digest::md5

I know nothing about the algorithm, and I haven't looked at the reference you gave, but are you sure about this line

$msgbin .= 0 until length $msgbin == 448 % 512;

448 % 512 is always going to be 448, so what's the point?