#!/usr/bin/perl use strict; use warnings; #open FILE, "foo" or die$!; #my @lines = ; my %map=(); my $datapos = tell DATA; foreach (grep(/,/, )) { chomp; my ($p1,$p2) = split /,/,$_; $map{$p1} = $p2; print '$map{',$p1,'} = \'',$map{$p1},"';\n"; } seek DATA, $datapos, 0; foreach (grep(!/,/, )) { chomp; print "$_ $map{$_}\n"; } __DATA__ apple,fruit pear,fruit zucchini,vegetable eggplant,vegetable potato,vegetable apple apple pear pear zucchini zucchini eggplant eggplant potato potato