if ($mail_id =~ /\A(box1|box2|box3|other1|other2)*\.(yourcompany|othercompany|elsewhere)\.com\z/ ) { print "matched\n"; }