Keeping the separators by having them in parentheses.
#!usr/bin/perl use warnings; use strict; my $string = "\nThis-is:a\@test-for,*you."; $string = join( ',', split( /([-:@*])/, $string )); print "$string\n\n";