use strict; use warnings; use Data::Dumper; my %stuff= split(/,|=/,do { open my $test, '<', 'test.txt' or die "I/O Error: $!\n"; local $/; $_=<$test>; $_=~s/[\r\n,]+/,/; }); print Dumper \%stuff;