use strict; use warnings; use Data::Dumper; my $b = 'test 200'; my %hash = ( c => ( $b =~ /([a-z]+)/ ? $& : 0 ), b => ( $b =~ /(\d+)/ ? $` : 0 ), a => ( $b =~ /\s+/ ? $' : 0 ), ); print Dumper(\%hash); #### $VAR1 = { 'c' => ' ', 'a' => '200', 'b' => 'test' };