my $record = { map {ref $_ eq 'HASH' ? %{$_->{record}} : ()} map {ref $_ eq 'ARRAY' ? @$_ : $_} @item[1 .. $#item] }; if (_is_field($item[0]) or $item[0] eq 'remaining') { $record->{$item[0]} = $text } $return = { text => $text, record => $record };