use File::Find; my ($search, $ext) = @ARGV; $ext = ".$ext" if defined $ext; @ARGV = (); find sub { push @ARGV, $_ if -f and not $ext or /\Q$ext$/ }, "."; while (<>) { close ARGV if eof; print "$ARGV: $. :$_\n" if /$search/; }