in reply to get it into one line ?

Just a gentle pointer

But that results in numberfilled array $newsearch string

The map function evaluates whatever is inside {} and returns the result from the last expression in the block. Thus, it's giving you a list of numbers generated from $sec{$char}++.