while(1) { my $match = $telnet->waitfor(Match => '/^--More--$/i', Match => '/^Mediant 800 >/i', Mathc => '/.*$/'); last unless defined $match; if ($match =~ /^--More--/i) { $telnet->print(' '); # ignore line } elsif ($match =~ /^Mediant 800 >/i) { # back at command prompt; last; } else { push @lines, $match; } }