Using a trick from the web site you linked to, this runs very quickly to get the 7 4-digit vampire numbers. $digits is the length of the factors; set it to 3 and it got the 6-digit numbers in a reasonable time, too (939658 = 986 * 953, for the largest example).
my $digits = 2;
my @mods;
for ([0,0],[2,2],[3,6],[5,8],[6,3],[8,5]) {
$mods[$_->[0]] = $_->[1];
}
my $min_factor = 1 . (0 x ($digits-1));
for my $a ($min_factor .. (9 x $digits)) {
if (defined $mods[$a % 9]) {
for (my $b = $min_factor - 1 + ($mods[$a % 9]||9); $b <= $a; $
+b += 9) {
my $prod = $a * $b;
my $fdigits = join '', sort map {split //} $a, $b;
my $pdigits = join '', sort split //, $prod;
if ($pdigits eq $fdigits) {
print "$a * $b = $prod\n";
}
}
}
}
Update: better way of excluding short factors.
Caution: Contents may have been coded under pressure.