use strict; use warnings; use File::Basename; while (my $line = ) { if ($line =~ /#include [<"](\S+\.h)[>"]/) { print basename($1), "\n"; } } __DATA__ #include "string.h" --> below code prints header #include --> below code prints header #include --> not able to get the header name(dispatch.h)