sub ident { my $s_pos = pos; RETRY: { local our $at_eof = ...; local our $need_more = 0; my $match = / \G (?: \z (?{ $need_more = !$at_eof }) )? [a-zA-Z_] (?> [a-zA-Z0-9_]* ) (?: (?= . ) | (?{ $need_more = !$at_eof }) ) /xsgc; if ($need_more) { ... pos = $s_pos; redo RETRY; } my $e_pos = pos; if ($match) { $_[0] = substr($_, $s_pos, $e_pos-$s_pos); return 1; } else { pos = $s_pos; return 0; } } }