use strict; use warnings; print filter($_), "\n" for ; sub filter { my $str = shift; defined $str or return ''; my $acceptable = 'a-z0-9_.'; $str =~ s/[^$acceptable]//gi; return $str; } __DATA__ Hello, world! te-st%$/*. All_of_this_is_OK. !@#$%^&*()12345 #### Helloworld test. All_of_this_is_OK. 12345