Others have answered the question you asked but I am going to propose a different solution which may be over-kill for what you are doing (ie you only ever want color or you can't guarantee the format of the line)
use strict; while (<FILE>){ chomp; my %line = map { split /\s*:\s*/ } split /\s*\|\s*/; print "color = $line{color}\n"; #or for my $key (keys %line){ print "$key = $line{$key}\n"; } }
This line my %line = map { split /\s*:\s*/ } split /\s*\|\s*/; does all the work. First at the far right we split the line up into chunks using the pipe (plus optional whitespace) as a seperator, we pass the chunks one at a time through map to another split which breaks each chunk into a pair based on the colon seperator (again with optional whitespace). The result is a list like (shape,square,color,red,size,320x320,id,0001) which we use to populate the hash. I don't know your experience as a programmer so this may seem very complicated, that's OK read the man pages, experiment, look at other peoples code, and don't be afraid to experiment.

--
Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho


In reply to Re: return a word next to the word you give by greenFox
in thread return a word next to the word you give by Anonymous Monk

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.