faster perl version, go version

Here's a faster perl version (fixed a bug), and a go version (not very optimal or idiomatic, I'm sure).