sub lexer { my($parser)=shift; my $s = $parser->YYData->{INPUT}; # reference to the string to lex m/\G\s+/gc; skip any spaces return ('INT', $1) if $$s =~ m/\G\(d+)/gc; return ('ID', $1) if $$s =~ m/\G([A-Z]\w*)/gc; ... # and it goes on for many tentative matches }