use strict; my @user = map { 'foo'.$_.'bar' } qw(! @ # $ % ^ & * ( ) _ .); for (@user) { print /^[\w.]+$/ ? "$_ is legal\n" : "$_ is illegal\n" ; }