open TXT, "<", $file) or die "Cannot open $file: $!"; while() { chomp; my @array = split ''; # 1 char per array item s/\s// foreach @array; # replace space with empty string ... }