use strict; my @file = ; my $word = "color:"; # no space after colon for my $lineno ( 0 .. $#file ) { if ($file[$lineno] =~ /\b$word\s*(\w+)/){ # notice the capture brackets my $value = $1; # $value here is 'red'. ... } }