while (my $line = ) { 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 #include "gfoo.h" #### 1 not match [not an include] 2 MATCH [#include "foo.h"] 3 not match [#include ] 4 not match [#include "gfoo.h"]