# always check the results of an open() open (FILE, $filename) or die "unable to open $filename for input: $!"; while () { # [1] omit line from output if it matches: # (make `[^.]*' more specific if only certain words should match) next if m~~; chomp; # [2] if (m!]*>!i ... m!]*>!i) { # modify body lines only # [3] replace .html with .asp in anchors in this line s~(href\s*=\s*") # capture beginning of anchor in $1 (?!http://) # _not_ followed by http:// ([^"]+) # capture base of filename in $2 \.html # match .html ~${1}${2}.asp~gix; # make substitution, global } print OUTFILE; }