while (readdir $dirH) { next if ($_ eq '.'|| $_ eq '..'); next if (! m/\@(?:\d{1,3}\.)\d{1,3}/); #ip of src of records if ( ! defined $Accts{$_}){ #new directory # open the new file and put handle in hash #open $Accts{$_}, "<$_/all/events.log"; open $Accts{$_}, "<$Cpath/$dateDir/$_/all/events.log"; } }