while ($url_stack is not empty) { $url = pop $url_stack; open URL $url; while () { my @words split / /, $_ # split a line into words # For each word in the line, see if it's a URL. Push # it to the stack and substitute the local path if it # is foreach my $word @words { if $word =~ m/^http:\/\//; push $word $url_stack; $word =~ s/'remote_path'/'local_path'/; } # join all the words together into a new line join @words my $output_line; # write that line into the local version of the file. print $output_line; } }