sub rel_path($$) { my ($target,$start) = @_; $start =~ s:/[^/]+:/:; # remove trailing filename my @spath = grep {$_ ne ''} split(/\//,$start); my @tpath = grep {$_ ne ''} split(/\//,$target); # strip common start of the path while ( @spath && @tpath && $spath[0] eq $tpath[0]) { shift @spath; shift @tpath; } return ("../"x(@spath)).join('/', @tpath); }