#!/usr/bin/env perl use strict; use warnings; use autodie; my $input_file = 'test_input.txt'; my $info = parse_input_file($input_file); #get $address for each line in input file # Assume "path", not "address". # Will only be for each "processed" line: # no comments or blanks. #get $name for each line in input file # Again, will only be for each "processed" line: # no comments or blanks. # You also seemed to want a list of fruits. my (@names, @fruits, @paths, %seen); for my $name (keys %$info) { push @names, $name; FRUIT: for my $fruit (keys %{$info->{$name}}) { push @paths, $info->{$name}{$fruit}; next FRUIT if $seen{$fruit}++; push @fruits, $fruit; } } # TODO - for demo only; remove for production use Data::Dump; print "Data extracted:\n"; dd $info; print "Names:\n"; dd \@names; print "Fruits:\n"; dd \@fruits; print "Paths:\n"; dd \@paths; sub parse_input_file { my ($file) = @_; my $info = {}; { open my $fh, '<', $file; while (<$fh>) { next if /^(?:#|\s*$)/; my ($name, $fruit, $path) = split; $info->{$name}{$fruit} = $path; } } return $info; }