my @hosts; while () { # log file lines have multi-character domain names at the start if (/^\w+/) { my $file = (split(/\|/, $_, 3))[2]; if ($file =~ s!/access_log\.(.+)$/) { push @hosts, $1; } } }