INPUT:- #include "string.h" -->works for below code #include --> words for below #include --> doesn't work,should work for all the three cases if ($line =~ /#include [<"](\S+\.h)[>"]/) { print "$1\n"; }