open F1, "file1" or die $!; while (my $find = ) { chomp $find; open F2, "file2" or die $!; while () { print if /$find/ .. /frame-relay/; } }