my $nth = 4; my $str = 'a,bb,ccc,dddd,eeeee,ffffff'; my @str= split /,/,$str; $str = join ( "," , @str[0..$nth-1] ) . "|" . join ( "," , @str[$nth..$#str] ); print qq{'$str'};