$start = time(); TEST1: while (){ $count = 0; foreach $value5(values %msgDefn) { $count ++; if ($_ =~/($value5)/){ print "Match found in $count iterations"; print $_; next TEST1; } } } $end = time(); print "Time taken was ", ($end - $start), " seconds";