in reply to string matching condition not working fine

Can you tell us what you're getting, and what you're expecting? This seems to work fine for me...

while (my $line = <DATA>) { chomp $line; if ($line =~ /(#include)( ")([^g]\w+)(\.)(\w+")/) { print "$. MATCH [$line]\n"; } else { print "$. not match [$line]\n" } } __DATA__ not an include #include "foo.h" #include <foo.h> #include "gfoo.h"
This produces:
1 not match [not an include] 2 MATCH [#include "foo.h"] 3 not match [#include <foo.h>] 4 not match [#include "gfoo.h"]