my $var='474627 asidase ta sidase ala,"lpha-D- ctoside gtohydrolase","razyme","arazyme (enz Corp)","Melie","lagal","idase bta", rug 00103'; my $tmp; $var =~ s{ ("[^"]+") }{ ($tmp = $1) =~ s/\t/ /g; $tmp }xge; my @each=split(/\t/,$var); for my $eachvar(@each) { print "$eachvar\n"; } #### # Using s{}{} form of substitute. # Substitute supports using several different separator formats # which helps one avoid having to escape things (like '/') within the pattern. # The 'x' option which means ignore whitespace so that comments can be easily inserted. # The 'g' option is global obviously. # The 'e' option says that the replacement part of the pattern is a perl expression. $var =~ s{ ("[^"]+") # Matches two quotes and content between them. # Capture the match for use in the replacement. # # Disection of pattern: # ("[^"]+") = full pattern # ( ) = capture everything between parentheses. # " " = quotes at start and end of pattern. # [^"]+ = one or more non-quote characters } { # The replacement part is a perl expression. # Original: ($tmp = $1) =~ s/\t/ /g; # is same as next 2 lines: $tmp = $1; # Make a copy of the captured match. $tmp =~ s/\t/ /g; # Replace tabs with spaces throughout the match. $tmp; # Use resultant value for replacement. }xge; # x = ignore white space and comments # g = global # e = expression