#!/usr/bin/env perl use 5.014; use warnings; use File::DirWalk; # Process commandline arguments die "usage: $0 pattern path ..." if (@ARGV < 2); my $pattern = shift; # @ARGV now contains one or more paths to recurse # Set up DirWalk object with callback to grep each file my $dw = new File::DirWalk; $dw->onFile(sub { my $file = shift; if (-T $file) { open my $fh, '<', $file or die "Can't open $file: $!"; print map { "$file: $_" } grep { /$pattern/ } <$fh>; close $fh; } return File::DirWalk::SUCCESS; }); $dw->walk($_) for @ARGV;