use warnings; use strict; my $str = 'a|b|c d e '; $str =~ s/[\s|]/_/g; print "$str\n"; $str = "w\nx\ny\nz"; $str =~ s/\n/ /g; print "$str\n"; __END__ a_b_c_d____e__ w x y z #### The regular expression: (?-imsx:\s|\(|\)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \( '(' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \) ')' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------