for my $hashref($HR_wnt,$HR_unx,$HR_component) { for my $id (keys %$hashref) { if ($id eq 'res.ldlibrarypath') { if ($$hashref{$id} =~ /=\//) { $$hashref{$id}=~ s/\/opt\/app\/$target.*?://; } } } }