foreach my $line (@port) { my @PORTS = split('\n', $line); foreach my $str (@PORTS){ ... } } }