Did you look at this (cpan.org), specifically the section on 'Searching'? There's an argument you can pass it that can be used as a filter, and that returns message numbers. Then you should be able to do what you want to do.
Hope that helps.
Comment on Re: Net::IMAP::Simple and Email::Simple printing, sorting, emailing, and deleting messages.