Adding Perl heuristic (and fixing up Prolog)