#! perl -slw use strict; use Data::Dump qw[ pp ]; my %config; while( <> ) { chomp; my @bits = split '[:|=]'; my $ref = \%config; $ref = $ref->{ shift( @bits ) } //= {} while @bits > 2; $ref->{ pop @bits } = pop @bits; } pp \%config;