open (FH, "filtered.txt"); open (IN, "information"); while () { chomp $_; /images\/(\d+)/; $sample = $1; print "$sample\n"; while (){ /(\d+)/; print "loop\n"; } } }