#Either local $_ = $$s; #Or s//$$s/; #tricky.. ;-) #### sub lexer { my ($parser) = shift; my $s = $parser->YYData->{INPUT}; # I don't get your line: 'm/\G\s+/gc; skip any spaces' my %dispatch = ( INT => qr/\G(\d+)/gc, ID => qr/\G([A-Z]\w*)/gc, #.. and so on .. ); while (my ($key, $regex) = each %dispatch) { return ($key, $1) if $$s =~ $regex; } }