* Fix ShellCheck warning 2219
https://github.com/koalaman/shellcheck/wiki/SC2219
* Replace GNU sed commands with perl
This replaces the sed commands which required GNU sed be installed with
perl versions. This should make this script more universally usable
(e.g., on macOS) without installing additional tools.