#!/usr/bin/perl use strict; use warnings; my %config; my $filename = "TestConfig.cfg"; open ( FILE,'<', $filename) or die "Cannot open file: $!"; while () { chomp; s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); $config{$var} = $value; } close FILE; while(my ($key, $value) = each(%config)) { print "key: $key, value: $value\n"; }