my @Filter = split /(port-channel \d\n)/, $Info; for (@Filter) { unless (/^port/) { # strip out the junk s/.*Ports://s; # Everything up to Ports:, even crossing line boundaries s/^\s+//m; # Leading spaces on lines s/\s.*//; # Everything from the first space to the end of a line } print; }