in reply to Printing just the file name for all the cases

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

Prints:

string.h stdlib.h sys/dispatch.h

which is what I understand you to want, so where's your problem?

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Printing just the file name for all the cases
by Anonymous Monk on Mar 20, 2011 at 08:49 UTC

    In the third case for sys/dispatch.h,I only want dispatch.h

      Modify the substitution to /#include [<"](?:\S+[\\\/])?(\S+\.h)[>"]/.

      True laziness is hard work