You can try to speed this up by collecting regular expressions.
I'm not sure how to do this using pure Perl 6, but Regexp::Assemble is a Perl 5 module that can do this for Perl 5 regular expressions. You can use Perl 5 modules in Perl 6 code by adding :from<Perl5> (without the previous space) to the use statement, and then accessing its exported characters (classes, objects, routines, etc.), as if it was Perl 6:
use v6; use Regexp::Assemble:from<Perl5>; my @array = "aaaaa" .. "fffff"; my @search = "aaaa" .. "cccc"; my $ra = Regexp::Assemble.new; $ra.add( @search ); $ra.anchor_string_begin(1); .put for @array.grep({so($ra.match( $_ ))});
source share