fancy the perl code?

Not sure how to suggest a pull request of only certain commits - the first one will rename all your ports, so you probably don't want that.. my git sucks too...