my $type_match = qr/#DO\s+$config{'type'}/i; foreach my $script_file ( @{ $config{'scripts'} } ) { open(SCRIPT_FILE, $script_file) or die "Can't open script file '$_': $!"; while ( my $line = ) { if ( $line =~ $type_match ) { print "File '$script_file' is the right type"; break; } } }