#!/usr/bin/perl -w $teststring = "Leeman.-"; print $teststring; print "\n"; $teststring = check($teststring); print $teststring; print "\n"; sub check ($string) { if ($string !~ /^[-.\w]+$/) { #words.. aka a-zA-Z_ and also - and . # print "unauthorized char"; #unauthorized char return "unauthorized char"; } else { # print "passed"; #passed return "passed"; } }