for my $i (0..$N-1) { my $substr = substr($s, $i); my @results = $trie->lookup($substr); for (@results) { ... } }