deletes messages if their subject contains the word "medicines":
require 'net/pop' mail_server = Net::POP3.new('mail.mailservernamehere.com') mail_server.mails.each do |m| m.delete if m.header =~ /Subject:.+?medicines\b/i end