or, more fancily, record what you replaced (e.g. in a hash, together with the character positions):
#!/usr/bin/perl -wl
use strict;
my $_field1 = 'Some Other - State & Non State';
my %invalid;
$_field1 =~ s/([^A-Za-z0-9\.\, ])/push @{$invalid{$1}}, pos($_field1);
+ ''/ge;
print "invalid char '$_' at pos @{$invalid{$_}}" for sort keys %invali
+d;
print "cleaned input: '$_field1'";
__END__
invalid char '&' at pos 19
invalid char '-' at pos 11
cleaned input: 'Some Other State Non State'
|