foreach my $fpc (@lines) { if ($fpc =~ /Slot (\d+?).*$/) { $slotcounter = 1; $slot = $1; next; } next unless $slotcounter eq 1; next unless ($cardtype, $pic) = $fpc =~ /PIC (\d+?)\s+(.*?)\,.*$/; next unless $cardtype =~ /$type/; ($ports = $cardtype) =~ s/^(\d)x.*/$1/; push @cardz, "so-$slot/$pic/$_" for 0 .. $ports - 1; }