my @out_arr = split (/\n/,$cmd_out); my @ts_arr; my $switch = 0; foreach (@out_arr){ if (/.*?10.72.184.159:disk_data_written.*/){ $switch = 1; } if(($switch == 1) && ($_ !~ /^\s*$/)){ push @ts_arr,$_; } if(($switch == 1) && (/^\s*$/)){ last; } } print "\n The timestamp array consists of : \n"; print @ts_arr;