open (EXT, "LDB_EXTID.lst") or die "something"; my @uids = ; # read in each line as a member of the array close EXT; # here's the key line ! chomp @uids; # remove any trailing newlines from every member of @uids foreach my $uid (@uids) { my $output = `ldbtest.pl -e $uid -t 123`; last if ++$counter > 10; } # stuff you'd do after the loop, if anything