#!/usr/bin/perl -w use strict; use Data::Dumper; my $datafile = "data.txt"; open(FILE,$datafile); foreach my $line () { #Kill linefeeds/returns. Data generated on variety of OS's $line =~ s/\n//g; $line =~ s/\r//g; my @items = split(/--/,$line); my $foo = &bhash(\%shash,@items); @shash{keys %$foo} = values %$foo; } close(FILE); print Dumper \%shash; sub bhash { my($hash,@keys )= @_; my $ref= \$hash; map($ref= \$$ref->{$_}, @keys); return $$ref; }