in reply to Re^2: Regex Parsing Chars in a Line
in thread Regex Parsing Chars in a Line

Maybe you could avoid the regex approach and use split and join?

# untested my @parts = split /-/, $input; my $first = shift @parts; my $last = pop @parts; my $reassembled; # then $reassembled = $first . '-' . join ('_', @parts) . '-' . $last; # or something like this $reassembled = join '_', @parts; $reassembled = join '-', ($first, $reassembled, $last);

The above assumes no CSV type quoting issues with embedded separators, for which a proper CSV parser like Text::CSV is needed.