use File::Find; use URI::URL; $DIR = shift || die "usage: $0 base [start]\n"; die "missing $DIR" unless -d $DIR; $START = shift || $DIR; die "missing $START" unless -d $START; find ( \&fixup, $START ); sub fixup { return unless /.html$/; my $filename = $File::Find::name; my $BASE = $filename; $BASE =~ s,[^/]+$,,; die "$file exists " if -e "$filename.orig"; local @ARGV = $filename; local $^I = ".orig"; warn "@ARGV\n"; while (<>) { s{ ( (HREF \s* = \s*) (['"]) ($DIR.*?) \3 ) }{ my ($all, $first, $quote, $file) = ($1, $2, $3, $4); if ( index($file, $DIR) == 0 ) { my $rel = url("file:$file", "file:$BASE")->rel(); $rel =~ s/#$//; $first . $quote . $rel . $quote; } else { $all; } }sgex; } continue { print; } }