You can do it with regsubex:
on @*:ban:#:{
tokenize 32 $regsubex($str(.,$nick(#,0)),$&
/./g,$iif($address($nick(#,\n),2) = $banmask,$&
$nick(#,\n)) $chr(32)) | kick # $* You have been banned!
}
I don't get why the author used ^ next to his ban event. The ^ indicates it's a custom event, where the script it's not considered one. ^ serves no purpose in this case.