use File::Find; find(\&wanted, @directories_to_search); # untested sub wanted { return unless -f $File::Find::name; my $f; unless ( open $f, '<', $File::Find::name ) { warn "couldn't open $File::Find::name: $!\n"; return; } my $matched; while (<$f>) { $matched = 1 if /word_to_look_for/; } print "found word_to_look_for in $File::Find::name\n" if $matched; }