in reply to Reg Ex exercise

You will want to use chomp, not chop.
Then you can put all your codes within a while loop more constructively.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me