@lines = split /\n/, $buffer; my ( $name, $end ) = ( '', '' ); for ( @lines ) { next if (/^\s*#/ or /^\s*$/ ); # skip comments, blank lines if ( $name ) { if ( /^$end$/ ) { chomp $config{$name}; #remove trailing "\n" $name = ''; } else { $config{$name} .= "$_\n"; } } elsif ( /(\w+)\s*=\s*(.*?)\s*$/ ) { # regular pair $config{$1} = $2; } elsif ( /(\w+)\s*=\s*<<(\w+)/ ) { # heredoc ( $name, $end ) = ( $1, $2 ); } else { warn "Ptooey: Could not parse config line: $_\n"; } }