If you don't mind losing the tab within the quotes, pre-process the string to remove those tabs. Here I replaced the embedded tabs with spaces, then just split on tab:

my $var='474627 asidase ta sidase ala,"lpha-D- ctoside gtohydrol +ase","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"; }

Update 1: Oops, I made a mistake in the pattern. The quotes belong on the inside of the capture. (Was: "([^"]+)", Now: ("[^"]+").

Update 2: In response to a private message, here's a little better explanation of the pattern:

# 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 pe +rl 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 pare +ntheses. # " " = quotes at start and end of patt +ern. # [^"]+ = one or more non-quote character +s } { # The replacement part is a perl expressio +n. # 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

In reply to Re^7: The best way to split tab delimited file by gmargo
in thread The best way to split tab delimited file by Ratna_Ranjan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.