open FILE, "<", "filename.txt" or die $! while () { if (($_ =~ /^$year\-/) && ($_ =~ /\Q $IP1 \E/) && ($_ =~ /\Q $IP2 \E/)) { print "packet match found!"; } }