Presuming any non-word character should be replaced with an underscore:
my $s = 'Hello ( World ).'; $s =~ s/\W+/_/g; # Replace all sequences of [^a-zA-Z0-9_] with _ $s =~ s/_$//; # Remove trailing _ if present
Note that if you wanted to replace strings containing multiple sequential _, you'd have to change \W to the appropriate character class.
In reply to Re^2: brackets help
by eibwen
in thread brackets help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |