Perl Module to split records based on various criteria