# As is, assumes at least 3 commas are found. my ($pre, $post) = /^((?:[^-]-){3})(.*)/s; $post =~ s/-/,/g; $_ = "$pre$post";