faster perl implementation
revert back; the new one is wrong
compatible with dart M3