use File::Find; my $ext = "dat"; my $nom = 0; find ( \&ripper, @ARGV) ; sub ripper { ## First implementation unless(s/\.$ext$//i) {return;} my $file = $_; #using $_ screws up grep $nom += unlink(grep(/\Q$wang\E\.(?!$ext)/, glob("*")),"\n"); } sub ripper2 { ## Second implementation my $file = $_; return unless(s/\.(?!$ext)$//i); my $priority = $_ . $ext; if(-e $priority && !-d $priority) { $nom += unlink $file; } }