use strict;
use warnings;
my $str ='"Transcription factor" promoter DNA "Transcription factor" p
+romoter DNA.';
my @str = split//, $str;
my $fla = 1;
for (@str){
if (($_ eq "\"") && $fla)
{
$fla = 0;
}elsif (($_ eq "\"") && !($fla)){
$fla = 1;
}
$_ =~ s/ /\,/ if ($fla);
}
print join'',@str;
__END__
Output:
-------
"Transcription factor",promoter,DNA,"Transcription factor",promoter,DN
+A.
TIMTOWTDI, we can achieve the expected output using RegExp as of below:
$str =~ s/((?:(?!\").)*)(\"[^\"]+\")((?:(?!\").)*)/
my $fi = $1;my $se = $2; my $th = $3;
$fi =~ s| |\,|g;$th =~ s| |\,|g;
"$fi$se$th"/egs;
Regards, Velusamy R. eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';
|