In the worst case, where you have some unusual, specific need that hasn't been designed for, you can -- quite easily -- easily create your own policy daemon [2] (even in Perl; see the example) and/or milters [3].
> I wouldn't say that. perl is about the best scripting language IMO, and is available on all systems.
Oh, I agree; I was mostly teasing. I first started using Perl c. 1995 (and later, for writing CGI scripts, when CGI became a thing) and it is still the scripting language I reach for 95% of the time for basic sysadmin stuff.
> I wrote my own spam filter because I want to have full control over how I deal with spam, and generally it works very well.
I certainly can't fault you for that. Take a look at the greylist.pl script that ships with Postfix. It is an example of a policy daemon that implements greylisting (not meant for production; for greylisting, use postscreen instead). It's been several years ago but, after looking at that, I was able to implement my first policy daemon (which reached out to a MySQL server) in about 20 minutes and, after some testing, put it into production shortly after that. It's amazingly simple.
I'm not sure what MTA you are currently using but I would certainly recommend looking into Postfix. Back in the 90s, I was a hardcore, bigoted sendmail guy ("Give me sendmail or give me death!") but at some point I started looking into Postfix and have never looked back. Among other things, I manage mail systems at $work (an ISP) and I'm "very anti-spam". I occasionally need/want to do some unusual things policy-wise (WRT accepting or rejecting mail) and Postfix can itself handle 95% of it. For the other 5%, I tweak AMaViS or write my own policy daemons.
N.B.: My personal mail server (currently) runs on FreeBSD, where I use OpenBSD's "spamd" [4] for greylisting. Personally, I prefer and use that over postscreen (it stops upwards of 90% of remote mail systems from even getting to talk to the "real" MTA!) but on my (CentOS) Linux-based mail systems, I now just use postscreen (previously, I had a "standalone" OpenBSD box running "spamd" sitting in front of Barracuda appliances (as a transparent SMTP proxy). postscreen is really simple to get up and running -- and even more so if you're already using Postfix! -- and a very minimal, basic postscreen configyration will stop the majority of "zombies", hijacked PCs, blacklisted hosts, etc., from getting through to your actual SMTP server.
[0]: http://www.postfix.org/postscreen.8.html
[1]: http://www.postfix.org/POSTSCREEN_README.html
[2]: http://www.postfix.org/SMTPD_POLICY_README.html