I'm not sure if you want to find the string _in_ the file, or in the filename.
############################ #in the file use strict; opendir(DIR,"."); foreach(readdir DIR){ if(HasText($_)){ unlink $_; } } sub HasText{ my $file = $_[0]; open(FILE,"$file"); while(<FILE>){ if($_ =~ /pattern/i){ return 1; } } } ############################ ############################ #in the filename use strict opendir(DIR,"."); foreach(readdir DIR){ if($_ =~ /pattern/){ unlink $_; } } ############################ I haven't tested these yet, but you get the idea... -----Original Message----- From: james [mailto:[EMAIL PROTECTED]] Sent: Monday, July 15, 2002 12:52 PM To: [EMAIL PROTECTED] Subject: unlinking all files that contain a specified string hi, all! friday while trying to clean up a directory, i thought i could bang out a quick-and-dirty perl script that would let me achieve what i needed, to delete all text files in a subdirectory that contain a specified string. i was able to use the perl command unlink(filename) and grep manually, but i couldn't seem to put them together in a script that would do what i needed. does anybody know how to do this? (i'm asking out of laziness so i'm hoping the person who answers this doesn't have to put much, if any, effort into doing so :)) thanks, james -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]