open( FILE, "file" ) || die ("The file not there "); while (<>){ if (m/$regex/) { print "matched!\n"; close (FILE); exit; } }