use strict; use warnings; use feature 'say'; use Data::Dumper; $Data::Dumper::Sortkeys = $Data::Dumper::Indent = 1; chomp( my $input = ); my ( $first, $txt ) = split / /, $input, 2; my %pairs = $txt =~ / ( \w+ ) # capture key = # separator ( # capture value (?: # group (but don't additionally capture) (?!\w+=) # (must not be followed by the next key-separator) .+? # at least one character (even if just the whitespace), non-greedy )+ # at least one of those ) # end value /msxg; $pairs{ $first } = ''; # trim trailing whitsepace from values $_ =~ s/ $// for values %pairs; say Dumper \%pairs; __END__ eab12345 id=00000 pgrp=abcdefgh groups=abcdefgh home=/home/eab12345 shell=/usr/bin/ksh gecos=AB/C/Y0000/ABC/XYZ RTYUI, LMNOP *CONTRACTOR* (AS 00000) auditclasses=general,files,TCPIP login=true su=true rlogin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=00 registry=AD SYSTEM=AD logintimes= loginretries=5 pwdwarntime=5 account_locked=false minage=0 maxage=13 maxexpired=0 minalpha=1 minother=1 mindiff=1 maxrepeats=2 minlen=8 histexpire=13 histsize=8 pwdchecks= dictionlist=/abc/def/ghi/jkl default_roles= fsize=-1 cpu=-1 data=-1 stack=65536 core=000000 rss=65536 nofiles=2000 time_last_login=1512632113 time_last_unsuccessful_login=1505304923 tty_last_login=ssh tty_last_unsuccessful_login=ssh host_last_login=0.000.000.000 host_last_unsuccessful_login=0.000.000.000 unsuccessful_login_count=0 roles= #### $VAR1 = { 'SYSTEM' => 'AD', 'account_locked' => 'false', 'admgroups' => '', 'admin' => 'false', 'auditclasses' => 'general,files,TCPIP', 'auth1' => 'SYSTEM', 'auth2' => 'NONE', 'core' => '000000', 'cpu' => '-1', 'daemon' => 'true', 'data' => '-1', 'default_roles' => '', 'dictionlist' => '/abc/def/ghi/jkl', 'eab12345' => '', 'expires' => '0', 'fsize' => '-1', 'gecos' => 'AB/C/Y0000/ABC/XYZ RTYUI, LMNOP *CONTRACTOR* (AS 00000)', 'groups' => 'abcdefgh', 'histexpire' => '13', 'histsize' => '8', 'home' => '/home/eab12345', 'host_last_login' => '0.000.000.000', 'host_last_unsuccessful_login' => '0.000.000.000', 'id' => '00000', 'login' => 'true', 'loginretries' => '5', 'logintimes' => '', 'maxage' => '13', 'maxexpired' => '0', 'maxrepeats' => '2', 'minage' => '0', 'minalpha' => '1', 'mindiff' => '1', 'minlen' => '8', 'minother' => '1', 'nofiles' => '2000', 'pgrp' => 'abcdefgh', 'pwdchecks' => '', 'pwdwarntime' => '5', 'registry' => 'AD', 'rlogin' => 'true', 'roles' => '', 'rss' => '65536', 'shell' => '/usr/bin/ksh', 'stack' => '65536', 'su' => 'true', 'sugroups' => 'ALL', 'time_last_login' => '1512632113', 'time_last_unsuccessful_login' => '1505304923', 'tpath' => 'nosak', 'tty_last_login' => 'ssh', 'tty_last_unsuccessful_login' => 'ssh', 'ttys' => 'ALL', 'umask' => '00', 'unsuccessful_login_count' => '0' }