use strict;
use warnings;
use DBI;

my %valid = ();

my $dbh = DBI->connect('DBI:mysql:pokedex', 'perl', '');
my $sth;

( $sth = $dbh->prepare('SELECT name FROM pokemon') )->execute;
while (my $name = ($sth->fetchrow_array)[0]) { $valid{ lc $name } = 1 }

( $sth = $dbh->prepare('SELECT name FROM moves') )->execute;
while (my $name = ($sth->fetchrow_array)[0]) { $valid{ lc $name } = 1 }

( $sth = $dbh->prepare('SELECT name FROM types') )->execute;
while (my $name = ($sth->fetchrow_array)[0]) { $valid{ lc $name } = 1 }

my @lines = grep { local $_ = $_; s/%([0-9a-f]{2})/chr hex $1/ie; chomp; not exists $valid{lc $_} } <STDIN>;

print @lines;
