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