my $kind; my $REGEX = qr/ [A-Za-z][\w]* (?{$kind = 'IDENT';}) | (?: ==? | != | <=? | >=? ) (?{$kind = 'OP';}) | -?\d+ (?{$kind = 'INT';}) | \x27 ( (?:[^\x27] | \x27{2})* ) \x27 (?{$kind = 'STRING';}) | \S (?{$kind = 'OTHER';}) /xs;