#!/usr/bin/perl #supply test strings on the command line for ease $test1 = shift(@ARGV); sub validate_text { if ( $test1 =~ m/^[A-Za-z0-9\-\ ]+$/ ) { print "Text clean\n"; return ($test1); } else { $errorstring = "Funny business with variables occuring, have attempted to fix"; print "$errorstring\n"; print "dollartest before fixing = $test1\n"; $test1 =~ s/^[^A-Za-z\-\ ]+$//g; print "dollartest after fixing = $test1\n"; return ($test1); } } $validated = &validate_text; print "the validated text is: $validated\n"; #### [lowprivuser@localhost testing]$ perl regexp-check2.pl abcd\"efg Funny business with variables occuring, have attempted to fix dollartest before fixing = abcd"efg dollartest after fixing = abcd"efg the validated text is: abcd"efg [lowprivuser@localhost testing]$ perl regexp-check2.pl abcdefg1 Text clean the validated text is: abcdefg1 [lowprivuser@localhost testing]$