The $file is only valid inside the foreach scope. To get a global value use:
use strict; use warnings; my $file # the variable is now global opendir(DIR,".") or die("Couldn't open the current directory!\n"); my @files = readdir(DIR); foreach $file(sort @files){ # The my has been removed in this line if($file =~ /(.*test.*)/i){ print "MATCH: $file\n"; } } Cheers Tommy [EMAIL PROTECTED] http://homepage.mac.com/tgrav/ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction" -- Albert Einstein