my $count; foreach (@sentence){ $count++; if (@sentence=~ m/$first/gsi){ print "Matched! at line $count\n"; print "@sentence[10]\n"; } }