it actually looks quite similar to yours instead of using a while loop for your $htmlfrm you can use $regsubex for faster results
alias htmlfrm return $regsubex($1-,/(\W)/g,$+(%,$base($asc(\1),10,16)))