open HANDLE, 'testhash.txt' or die "Can't open: $!"; for my $data () { chomp $data; my %hash; foreach my $pair (split /'/, $data) { next if $pair eq ''; next if $pair =~ /^,$/; my ($key, $value) = split /,/, $pair; $hash{$key} = $value; } # do interesting things with one-line %hash here } close HANDLE;