Adding an input filter to automatically replace text with HTML via a script
I would rewrite the relatively short script. This shouldn't be a problem because you can re-use the Perl Regex in PHP, see http://php.net/manual/en/book.pcre.php

More Drupal specific would be caching. Add a cache tag to the filter result

  public function process($text, $langcode) {
    ...
    $result = new FilterProcessResult($text);
    $result-&gt;addCacheTags(['mymodule:filter']);
    return $result;
  }


so that you can invalidate the cached entities when the replacement text file gets updated:

\Drupal::service('cache_tags.invalidator')-&gt;invalidateTags(['mymodule:filter']);