use strict; use warnings; while (my $line = ) { if ($line =~ /#include [<"](\S+\.h)[>"]/) { print "$1\n"; #not printing the header third case } } __DATA__ #include "string.h" #include #include #### string.h stdlib.h sys/dispatch.h