while(){ $_=~s/\s+//g; push(@array1,$_); } my %s = (); $s{$_}++ for @array1; #### N01A0000.fBG1_c22 N01A000X.fBG1_c5 N01A000X.rBG1_c5 ... #### my %s; while() { s/\s+//g; $s{$_}++; }