# UNTESTED my @line_regexs = ( qr/(Packet ID)\s+\(hex\)\s+(\w+)\s+(Origin)\s+([\w\s]+)/, qr/(Date) \s+ \(mm\/dd\/yyyy\) \s+ (\d{2}\/\d{2}\/\d{4}) \s+ (Qualifier) \s+ (\w+) /x, # ... ); my ($count,%hash) = (1); open my $fh,'<', $path or die $!; LINE: while( <$fh> ){ chomp; foreach my $r ( @line_regexs ){ if( /$r/ ){ $hash{$count}{$1} = $2; $hash{$count}{$3} = $4; next LINE; } } $hash{ $count++ }{'Error Message'} = $_ } close $fh;