my $change = 1; while ($change) { $change = 0; $change ||= s/^($pattern)/$h_orig->{$1}/g for values %copy; }