#!/usr/bin/perl use strict; use warnings; my @array=( 21112340, 21112341, 21112342, 21112343, 21112344, 21112345, 21112346, 21112347, 21112348, 21112349, 21112350, 21112351, ); my %test; for(@array) { $test{$1}+=2**$2 if($_=~/^(\d{7})(\d)/); } my @new_array; for my $val (@array) { my $v=substr($val,0,7); if($test{$v} && $test{$v}==(2**10)-1) { push(@new_array,$v) if(!@new_array or $new_array[-1]!=$v); } else { push(@new_array,$val) } } print "$_\n" for(@new_array);