in reply to 'Permission Denied' error from File::Find

First and foremost, I think you should add the $file to the error message. Then, when you get an error, you can go and double-check the file manually to verify that you have 'read' access to it.

Second, and just as important, you should return from the subroutine when there's an error. As it is, you carp... but then you execute the rest of the sub anyway.

As written, you're only searching for matches in the first line of each file encountered. If that's not what you want, you might try simply undefining $/ locally in the sub.

Here's how I'd probably modify your code:

sub search { my $file = $File::Find::name; unless ( open FILE, "< $file" ) { carp "Error opening $file for reading - $!\n"; return; } local $/; # sluurp (if appropriate) my $line = <FILE>; close FILE; print "$text - $file" if $line =~ /$text/; }
(But, TIMTOWTDI, as always...)

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.