sub rnchrpos { my ($str, $chars, $pos) = @_; $pos ||= $pos; $pos += length $str if $pos < 0; return ( substr($str, 0, $pos) =~ /[\Q$chars\E]*\z/ ? $-[0] - 1 : -1 ); }