while(){ $_=~s/\s+//g; push(@array1,$_); } my %s = (); $s{$_}++ for @array1;