#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $cnf_file = q{config.txt}; my %cnf = read_config($cnf_file); print Dumper \%cnf; sub read_config { my $file = shift; open my $fh, q{<}, $file or die qq{cant open *$file* to read: $!}; my %cnf; while (my $line = <$fh>){ chomp $line; next unless $line; next if $line =~ /^#/; my ($key, $value) = split /\s+=\s+/, $line; if ($key eq q{To}){ push @{$cnf{$key}}, $value; } else{ $cnf{$key} = $value; } } return %cnf; } #### $VAR1 = { 'MediumAlarmThreshold' => '2', 'SMTP_Server' => 'smtp.isp.com', 'LowAlarmThreshold' => '3', 'LogRotateHour' => '0', 'To' => [ 'emailaddress@yahoo.ca', 'someotheremailaddress@yahoo.ca' ], 'HighAlarmThreshold' => '1', 'From' => 'Script@domain.com' };