Capturing the output of top in graphical mode (think it uses curses) is probably not what you want. If you use top's batch mode instead, capturing is much easier, you don't even need Expect:
open PIPE, "top -b -n 1 |" or die "Cannot open";
my $output = join '', <PIPE>;
close PIPE or die "Running top failed";