#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $infile = '/media/Docs/Scripts/Perl/Putty/TEST.csv'; open (CSVFILE, $infile) || die ("Could not open $infile! $!"); my @final; while ( my $line = ) { $line =~ tr/"\r\n//d; my @cleanline = split /,/, $line; my ( undef, @prefinal ) = split /\\/, $cleanline[ 1 ]; push @final, [ @prefinal, @cleanline[ 0, 3 ] ]; } close $infile; my %hash; foreach my $leaf (@final) { my $ptr = \%hash; foreach my $i ( 0 .. $#$leaf - 1 ) { my $node = $leaf->[$i]; if( $i != $#$leaf - 1 ) { $ptr->{$node} = {} unless( exists $ptr->{$node} ); $ptr = $ptr->{$node}; } else { $ptr->{$node} = $leaf->[$i + 1]; } } } print qq(\n); foreach my $k1 (sort keys %hash) { print qq( <$k1>\n); foreach my $k2 (sort keys %{$hash{$k1}}) { print qq( <$k2>\n); foreach my $k3 (sort keys %{$hash{$k1}{$k2}}) { print qq( <$k3>\n); print qq( $hash{$k1}{$k2}{$k3}\n); print qq( \n); } print qq( \n); } print qq( \n); } print qq(\n); exit(0);