$value =~ s{%(?:\[([^\]%]+)\])?([^%]*)%}{ if ($2 eq '') { '%' } elsif ($1 eq '') { if (exists $INIhashref->{$sectionname}{$2}) { $INIhashref->{$sectionname}{$2} } else { my $found; foreach my $section (values %$INIhashref) { if (exists $section->{$2}) { $found = $section->{$2}; last; } } $found } } else { $INIhashref->{$1}{$2} } }ge;