{ '/a/b/c/dt/data/SUSE/tool/0.9.0' => '/a/b/c/dt/tools/SUSE/tool/0.9.0', '/nfs/us/tools/SUSE12' => '/usr/bin', '/a/b/c' => '/p' }; #### realpath /p # Yields /a/b/c #### { '/a/b/c/dt/data/SUSE/tool/0.9.0' => '/p/dt/tools/SUSE/tool/0.9.0', '/nfs/us/tools/SUSE12' => '/usr/bin', '/a/b/c' => '/p' }; #### foreach my $actual_path_to_check (keys(%{$virtual_paths_href})) { foreach my $current_actual_path (keys(%{$virtual_paths_href})) { next if ($actual_path_to_check eq $current_actual_path); if ($virtual_paths_href->{$current_actual_path} =~ /^$virtual_paths_href->{$actual_path_to_check}/) { # Replace } } }