while (my $line = <$FH_IN>) { chomp $line; #removes line break or new line; my $url_sub = ""; print "processing file $counter,\n"; # Within each record, loop until a match occurs with "subsid" in the record,; # and the record contains a URL address, and the URL contain a derivative; # of Exhibt 21, e.g., ex21, ex-21, exhibit21, or exhibt-21; while ($line =~ m/subsidiar/igm && $line =~ m/\/Archives(.*)">/igm && ($line =~ m/ex21/igm || $line =~ m/EX\-21/igm || $line =~ m/exhibit\-21/igm || $line =~ m/exhibit21/igm) ) { $url_sub = $1; #extract the match and assign to variable; #Join the match with the standard URL prefix; my $url = join("",$base_url,$url_sub); print $url; open my $FH_OUT, '>>',$write_dir or die "Can't open file $write_dir >:$!>"; print $FH_OUT "$url\n"; ++$counter; } #End of while loop for extracting matching text; } #End of record;