#!usr/bin/perl use warnings; use strict; use Data::Dumper; my @lines = ('Nov 19 06:31:17 proxy postgrey[2439]: action=pass, reason=triplet found, client_name=r41.newsletter.otto.de, client_address=185.15.51.41, sender=otto@newsletter.otto.de, recipient=some.one@some.domain' ,'Nov 19 06:37:45 proxy postgrey[2439]: action=pass, reason=triplet found, client_name=uspmta194080.emarsys.net, client_address=217.175.194.80, sender=suite17@xpressus.emarsys.net, recipient=other.one@some.domain'); foreach my $line (@lines) { my $hash_ref = parseline ($line); my %tokens = %$hash_ref; print "line=$line\n"; foreach my $key (keys %tokens) { print "key=$key \t value=$tokens{$key}\n"; } print "\n"; #blank line spacer } # parse line creates a hash of keys and values representing # the contents of the line sub parseline { my $line = shift; my %tokens; my ($beginning_tag, $rest) = split (': ', $line,2); #space after the : required %tokens = ($rest =~ /(\S+)=(.+?)(?:,|$)/g); $tokens{tag} = $beginning_tag; return \%tokens; } __END__ Prints: line=Nov 19 06:31:17 proxy postgrey[2439]: action=pass, reason=triplet found, client_name=r41.newsletter.otto.de, client_address=185.15.51.41, sender=otto@newsletter.otto.de, recipient=some.one@some.domain key=client_address value=185.15.51.41 key=action value=pass key=reason value=triplet found key=recipient value=some.one@some.domain key=tag value=Nov 19 06:31:17 proxy postgrey[2439] key=client_name value=r41.newsletter.otto.de key=sender value=otto@newsletter.otto.de line=Nov 19 06:37:45 proxy postgrey[2439]: action=pass, reason=triplet found, client_name=uspmta194080.emarsys.net, client_address=217.175.194.80, sender=suite17@xpressus.emarsys.net, recipient=other.one@some.domain key=reason value=triplet found key=recipient value=other.one@some.domain key=action value=pass key=client_address value=217.175.194.80 key=client_name value=uspmta194080.emarsys.net key=tag value=Nov 19 06:37:45 proxy postgrey[2439] key=sender value=suite17@xpressus.emarsys.net