for($l=0; $l<$#sorted; $l++) { splice(@sorted, $l, 1) if substr($sorted[$l],0,7) eq substr($sorted[$l+1],0,7); }