while() { chomp; if ($_ =~ m#^(\d+)/(\d+)/(\d+)\s+.*admin2;user) { open(FH$3, ">$3.$2.$1"); print "$_\n" FH$3; } }