for($i = 0; $i < scalar($#file +1); $i++) { foreach ($file[$i]) { # <-- this is what solves it! chomp; ($stuff, $more_stuff) = split(/\|/); # ... } }