#!/usr/local/bin/perl 

use File::Find;

$expr = shift;

sub match
{
 if ($unsure)
  {
   return 1 unless (/#!.*perl/);
   $unsure = 0;
  }
 if (/$expr/o)
  {
   print "$File::Find::dir/$file:$.: $_" 
  }
 return 0;
}

sub wanted
{
 $File::Find::prune = 0;
 if (-T $_ && !/%$/)
  {
   local $unsure = !/\.p[ml]$/;
   local $file   = ($_);
   local ($_);
   open($file,"<$file") || die "Cannot open $file:$!";
   while (<$file>)
    {
     last if &match;
    }
   close($file);
  }
 elsif (-d $_)
  {
   $File::Find::prune = 1 if ($_ eq 'blib');
  }
}

@ARGV = '.' unless (@ARGV);

find(\&wanted,@ARGV);
