while (<$filename>){ while (/$id1/g && /$id2/g) { print "$file:$.\n"; } }