Replace `sed` with `perl` in build-support scripts

This replaces `sed` with `perl`, as `sed` caused nasty issues with
implementations on different platforms behaving slightly different.

As invoking a subshell using the backticks-syntax didn't always work,
all invocations of a subshell are now done using the dollar-parentheses-
syntax.

Fixes #45.