use warnings; use strict; foreach(){ chomp; # Skip blank or comment lines. next if /^\s*$|^\s*;/; # Trim comments from the end of lines. s/\s*;.*$//; my ($key,$val)=split /\s*=\s*/; $ENV{$key} = $val; $ENV{$key} =~ s/%([^%]+)%/$ENV{$1}/g; print "$key = $ENV{$key}\n"; } __DATA__ ; ;comments PROJECT_HOME=D:\Scripts\Projectname\ ;comments package1=pack_test package1_home=%PROJECT_HOME%%package1% #### PROJECT_HOME = D:\Scripts\Projectname\ package1 = pack_test package1_home = D:\Scripts\Projectname\pack_test