sub find { my $self = shift; my @terms = @_; use re 'eval'; $End_Of_String = 0; #### my @regex_tokens = map { my $yp = YAPE::Regex->new($_); my $str = ''; my $token; while ($token = $yp->next()) { $str .= $token->string() . '(?:\z(?{$End_Of_String++})(?!)|)'; } qr/$str/; } map { if ( not ref($_) ) { qr/\Q$_\E/; } elsif ( ref($_) eq 'Regexp' ) { $_; } else { my $string = "$_"; qr/\Q$string\E/; } } @terms; #### my $re = '(' . join( ')|(', @regex_tokens ) . ')'; my $compiled = qr/$re/s; #### while (1) { my @matches = $self->{buffer} =~ $compiled; if ($End_Of_String or not @matches) { $End_Of_String = 0; return undef unless $self->fill_buffer(); next; } else { my $index = undef; for ( 0 .. $#matches ) { $index = $_, last if defined $matches[$_]; } die if not defined $index; # sanity check my $match = $matches[$index]; $self->{buffer} =~ s/^(.*?)\Q$match\E//s or die; return ( $1, $match ); } } }