Hello, your regex is anchored to the end of string with the $ anchor at the end of pattern. this seems not correspond to your description of the problem. More: your $_ inside the grep is each element of @a and you built the hash using partial strings of @b not @a aka not true by definition.
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.