my $parser = parser { my $input = shift; return unless defined $input; my $next = head($input); for my $i (0 .. $#$wanted) { next unless defined $wanted->[$i]; return unless $wanted->[$i] eq $next->[$i]; } my $wanted_value = $value->($next, $u); my $tail = tail($input); # is this the last token from the stream? if ($tail && 'ARRAY' eq ref $tail && 'ARRAY' ne ref $tail->[0]) { $tail = [ $tail ]; } return ($wanted_value, $tail); };