open (FIND_CMD, "find /home/modules |"); chomp (my @findArr = ); #### my $pattern = '.pm$'; my $FilePattern = "sub user_method"; my $ResultFilePath = '/tmp/ModuleSearch'; foreach my $File ( @findArr ) { next if ( $File !~ m/$pattern/ ); #### system ("grep -iHl \"$FilePattern\" \"$File\" >> $ResultFilePath "); #### #!/usr/bin/perl use strict; use warnings; open my $find, '-|', 'find /home/modules -name "*.pm"' or die "Can't run find(1): $!\n"; $\="\n"; while (<$find>) { chomp; open my $fh, '<', $_ or die "Can't open `$_': $!\n"; while (my $line=<$fh>) { print, last if $line =~ /sub user_method/; } } __END__ #### #!/usr/bin/perl -ln use strict; use warnings; BEGIN { @ARGV='find /home/modules -name "*.pm"|' } local @ARGV=$_; /sub user_method/ and (print $ARGV), last while <> ; __END__