use strict; use warnings; my $str = " text with';*()/? nasty chars. scripted is ok, but not script"; sub cleanup { my $p = shift; return '' unless defined $p; $p =~ tr|<>;()"'?/*||d; $p =~ s/\bscript\b//g; return $p; } sub cleanup2 { $_[0] =~ tr|<>;()"'?/*||d; $_[0] =~ s/\bscript\b//g; return $_[0]; } print "\$str is: $str\n"; print "Cleaned up: " . cleanup($str) . "\n"; print "\$str is: $str\n"; print "Cleaned up: " . cleanup2($str) ."\n"; print "\$str is: $str\n"; #### $str is: text with';*()/? nasty chars. scripted is ok, but not script Cleaned up: some text with nasty chars. scripted is ok, but not $str is: text with';*()/? nasty chars. scripted is ok, but not script Cleaned up: some text with nasty chars. scripted is ok, but not $str is: some text with nasty chars. scripted is ok, but not