in reply to Character class in an array

This works well, except that it also accepts space(' ') as a valid character.

This is because of array interpolation, which uses the contents of $" to separate array elements when joining them together. You can use this to your advantage by doing something like

@a = ( 'a', 'x', 'z' ); # simplified array while(<>) { local $" = ""; print if(/^[@a]{3}$/); }
Note that this re-localizes $" within a loop, which isn't the most effecient approach, but then again you might not notice the performance difference without a microsocope.