while () { my $hit = parse_line($_); #do a bunch of stuff with the hashref, like # insert it into a DB. } sub parse_line { my $line = shift; if ($line =~ /^(\S+).*?\[(\S+).*?] (\S+) "([^"]+)" (\d+)/) { return {host_ip=>$1, timestamp=>$2, vhost=>$3, request=>$4, HTTP_CODE=>$5 }; # and some stuff to handle errors, that needn't bother us }