Being a Perl newbie, please pardon me for asking this basic question.

I have a text file @server1 that shows a bunch of sentences (white space is the field separator) on many lines in the file.

I needed to match lines with my keyword, remove the same lines, and extract only the last field, so I have tried with:

```
my @allmatchedlines;

open(output1, "ssh user1@server1 cat /tmp/myfile.txt |");

    while(<output1>) {
            chomp;
            @allmatchedlines = $_ if /mysearch/;
    }
    close(output1);

    my @uniqmatchedline = split(/ /, @allmatchedlines);

    my $lastfield = $uniqmatchedline[-1]\n";
    print "$lastfield\n";

```

and it gives me the output showing:
1

I don't know why it's giving me just "1".

Could someone please explain why I'm getting "1" and how I can get the last field of the matched line correctly?

Thank you!