You have two captures in the regex so for each match you get two entries added to @hits. However one of the captures will be undef because only one of the captures will match. Instead you could:
print '|', join ('|, ', "caaat" =~ m/( (?<=c)a | (?<=k)t )/gx), "|\n";
Prints:
|a|
Note that if you are using strictures (use strict; use warnings;) you will have received a 'Use of uninitialized value ...' warning.
In reply to Re: empty hits with regex
by GrandFather
in thread empty hits with regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |