if ($line =~ /\#include "\w".h | \#include <\w>.h)) #check if it is of the format #include "word.h" or #include { my $header_file = $line =~/\#include \"(\w)\".h| /#include\<\w>.h> #get only the header file }