foreach my $line ( @file ) { if ($line=m/^\s*$subname\s*:\s*(\S*)/i) { do something, we found it } }