$x = 'ABCD----[this] fgab [that] AB CD EF -- [foo]'; $x =~ s/\s*([^\[]+?)\s*\-*\s*\[([^\]]+)\]/$myhash{$1} = $2;/ge; print Dumper(\%myhash);