in reply to Finding specific keyword in Perl
Another option is to regex your file's slurped contents:
use Modern::Perl; my $fileContents = <<END; 0.0.0.0/0 *[Static/5] 02:30:27 > to 192.168.4.126 via em0.0 10.0.0.36/30 *[OSPF/10] 01:46:15, metric 2 > to 10.0.0.106 via em1.0 [BGP/170] 01:43:15, localpref 100, from 10.0.0.131 AS path: I 10.0.0.128/32 *[Static/5] 02:22:14 > to 10.0.0.110 via em2.0 [OSPF/10] 01:46:15, metric 3 > to 10.0.0.106 via em1.0 END { local $/; open my $fh, '<', \$fileContents or die $!; my $data = <$fh>; my @IPs = $data =~ /Static.+Static.+> to ([\d.]+) via.+> to ([\d.] ++) via/s; say for @IPs; }
Output:
10.0.0.110 10.0.0.106
|
|---|