use strict; use warnings; use Data::Dumper; my $s = q{ ABC: 123 xyz: 100 def: YYY aaa: ZZZ}; my %extract = map { split m{\s*:\s*} } split m{(?Dumpxs( [ \ %extract ], [ q{*extract} ] ); #### %extract = ( 'ABC' => '123', 'def' => 'YYY', 'aaa' => 'ZZZ', 'xyz' => '100' );