foreach (@sorted_data) { push(@data_out, $_) unless ($seen{substr($_,0,7)}++); }