How to assign the some corner atoms to a set of CNT using perl script?

Dear all,

I need to define the two sets consisting some atoms near end corner of CNT in Material Studio 18? Any help…