Hacked it together in perl.