use strict; use warnings; use feature 'say'; use Data::Dump 'dd'; use Time::HiRes 'time'; use PDL; use List::Util 'reduce'; use constant DICTIONARY => './354984si.ngl'; use constant TEMPLATE => 'neocene'; open my $fh, '<', DICTIONARY; chomp( my @dictionary = <$fh> ); close $fh; my $width = reduce { $a > length $b ? $a : length $b } 0, @dictionary, TEMPLATE; my $height = @dictionary + 1; my $words = zeroes byte, $width, $height; my $data = pack "(A$width)*", @dictionary, TEMPLATE; ${ $words-> get_dataref } = $data; $words-> upd_data; my $t = time; $words-> inplace-> setvaltobad( 32 ); my $table = $words-> dummy( 0, $width ) == $words-> dummy( 1, $width ); $words-> inplace-> setbadtoval( 32 ); $table-> badflag( 0 ); my $mask = ( $table == $table-> slice( '', '', -1 )) -> clump( 2 ) -> bandover -> slice([ 0, -2 ]) -> dummy( 0, $width ); my @found = split ' ', ${ $words-> where( $mask )-> get_dataref }; say time - $t; dd \@found; __END__ 1.04205107688904 ["kaitaka", "lauhala", "metreme", "neocene", "tempete"]