Wordle, love it or hate it, has grabbed the popular imagination for many. It is a solo puzzle game that is like Mastermind, but with words and you have but six tries to figure out the 5 word puzzle.

Of course, this is a task for Perl

#!/usr/bin/env perl
use strict;
use warnings;

sub main {
    my ($pattern, $exclude) = @ARGV;

    if (!$pattern) {
        die("$0 [PATTERN] [EXCLUDE]");
    }
    $exclude //= "";

    open my $wordsFH, "<", "/usr/share/dict/words" or die("words: $!");
    while (my $word = readline($wordsFH)) {
        chomp ($word);
        next if length($word) != 5;
        if ($word =~ /^$pattern$/i) {
            if ($exclude) {
                if ($word =~ /[$exclude]/) {
                    next;
                }
            }
            print "$word\n";
        }
    }
    close $wordsFH;
}

main();

Give it a regex pattern to match like ‘gr.at’ and an optional list of letters you know are not in the solution to get back the list of possible words that fit the pattern.

No, I didn’t take the fun out of this game — you did.