Think about it this way... every time you call the method on your object, it's basically like calling a subroutine which returns a string (because it does). However, because you're calling that method while the regex matches, it starts anew each time...
You: Ok, run the method. Regex: Wow, here's match #1... return $1 You: print(); Ok, run the method... Regex: Wow, here's match #1... return $1