in reply to Can anyone tell me what this is doing?
It looks like what someone is trying to do is take the text in $pages[$PG] and trim off everything after the final "end" line. It also looks like they don't understand array slices.