|more useful options|
Welcome to the Monastery!
Please pay attention to the posting rules, especially the one about enclosing your code in ... tags. It makes the code much easier to read, which results in more people wanting to help you.
First for a line by line comment on you code the way you wrote it...
Um... you commented out use strict and use warnings? That's like telling the compiler "I don't need your help! I know what I'm doing! I'm certain!". Leave them in and fix the errors that show up. For instance...
Use strict requires that every variable be declared with my (or with "our" or "state" in more complicated cases.)
To fix the coloring, while still following your original logic, I would change
to something like
I am printing out the section before each match, switching to green, printing the match, then switching back to black (it doesn't do that automatically.) Note the extra $printed variable is there to keep track of where the last match ended.
which fixes two problems; one is an extra comma after the position of the last match, because join was putting a comma between the last element of @c and the "\n". The second is that it was printing an extra "1". That's because the second print was interpreted as a function call. The print function works like the print statement but it also returns a value, usually 1 to indicate that it worked.