rewrote slow perl filtering script in D