in reply to return a word next to the word you give

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