in reply to Tell or determine whichever Perl regex group fails

Because this is Perl, There Is More Than One Way To Do It. The re module is in core, and will produce a trace of both the compilation and execution of a regular expression. In this case:

$  perl -Mre=debug -e '"okoK" =~ /(o|k)(k|i)(O|K)(K)/'
Compiling REx "(o|k)(k|i)(O|K)(K)"
Final program:
   1: OPEN1 (3)
   3:   TRIE-EXACTko (9)
        <o> 
        <k> 
   9: CLOSE1 (11)
  11: OPEN2 (13)
  13:   TRIE-EXACTik (19)
        <k> 
        <i> 
  19: CLOSE2 (21)
  21: OPEN3 (23)
  23:   TRIE-EXACTKO (29)
        <O> 
        <K> 
  29: CLOSE3 (31)
  31: OPEN4 (33)
  33:   EXACT <K> (35)
  35: CLOSE4 (37)
  37: END (0)
anchored "K" at 3..3 (checking anchored) stclass AHOCORASICK-EXACTko minlen 4 
Matching REx "(o|k)(k|i)(O|K)(K)" against "okoK"
Intuit: trying to determine minimum start position...
  doing 'check' fbm scan, 3..4 gave 3
  Found anchored substr "K" at offset 3 (rx_origin now 0)...
  (multiline anchor test skipped)
Intuit: Successfully guessed: match at offset 0
   0 <> <okoK>               |   0| 1:OPEN1(3)
   0 <> <okoK>               |   0| 3:TRIE-EXACTko(9)
   0 <> <okoK>               |   0| TRIE: State:    1 Accepted: N TRIE: Charid:  1 CP:  6f After State:    2
   1 <o> <koK>               |   0| TRIE: State:    2 Accepted: Y TRIE: Charid:  0 CP:   0 After State:    0
                             |   0| TRIE: got 1 possible matches
                             |   0| TRIE matched word #1, continuing
                             |   0| TRIE: only one match left, short-circuiting: #1 <o>
   1 <o> <koK>               |   0| 9:CLOSE1(11)
   1 <o> <koK>               |   0| 11:OPEN2(13)
   1 <o> <koK>               |   0| 13:TRIE-EXACTik(19)
   1 <o> <koK>               |   0| TRIE: State:    1 Accepted: N TRIE: Charid:  1 CP:  6b After State:    2
   2 <ok> <oK>               |   0| TRIE: State:    2 Accepted: Y TRIE: Charid:  0 CP:   0 After State:    0
                             |   0| TRIE: got 1 possible matches
                             |   0| TRIE matched word #1, continuing
                             |   0| TRIE: only one match left, short-circuiting: #1 <k>
   2 <ok> <oK>               |   0| 19:CLOSE2(21)
   2 <ok> <oK>               |   0| 21:OPEN3(23)
   2 <ok> <oK>               |   0| 23:TRIE-EXACTKO(29)
                             |   0| TRIE: failed to match trie start class...
Match failed
Freeing REx: "(o|k)(k|i)(O|K)(K)"

If you are using Windows, you will need to use " where my example has ', and vice versa.