http://www.perlmonks.org?node_id=557772


in reply to Counting the start and end elements in a line

well, it does not directly answer your question, but please use "use strict;" and also "use warnings;"