The STDERR did not provide any output. Only see something if I 'print' to document. See example output above where it matches after total. It does print based on the match but if I put Last WID before print, it does not print. Only prints if followed by Last WID.
My sense is that since I don't completely understand the top of the code (I did not write it), from what I see it's putting everything into $x and then performing the matching and print operations after. So ending the foreach comes too late. I think I'd have to delete everything at the end of the array after I first match total.