#!/usr/bin/perl use strict; use warnings; # 777297 my $data_file = "test1.txt"; open(DATA, $data_file) || die("Could not open file!"); my @data_file = ; my $names_file = "code.txt"; open(NAMES, $names_file || die "Could not open file!"); my @names_data = ; # create loop that reads each ID in code.txt (NAMES array), searches for each in array elements for #test1.txt # (DATA array), redirects a new (NAMES).html for each element my ($names, $data); for $names(@names_data) { chomp($names); for $data(@data_file) { chomp ($data); if ($data =~ /$names/) { print "found \$data ( $data ) in \$names \n"; } } } close NAMES; close DATA; #### 12345 34567 89246 54321 98765 #### </head> <body> <p><span class="b">12345 </span> foobar</p> <p><span class="b">54321 </span></p> <ul><li>89246</li></ul> <div id="second">34567 <br>78912 but this one ain't there</div> </body> </html> ##</code><code>## found $data ( 12345 ) in $names found $data ( 34567 ) in $names found $data ( 89246 ) in $names found $data ( 54321 ) in $names found $data ( 98765 ) in $names