@data_out = uniq(@sorted_data); sub uniq { my @xs=@_; my $x=shift @xs; return $x unless @xs; return (uniq(@xs)) if grep {substr($x,0,7) eq substr($_,0,7)} @xs; return ($x,uniq(@xs)); }