foreach(@sessions){ my @lines=split "\n",$_; foreach(@lines){ my ($port,$user,$host,$type,$dir,$status,$start,$idle)=split /\s+/,$_; # do stuff on each line here, probably want to ignore the header lines } }