open my $infile, "<", "test.txt" or die "cannot open input: $!"; my @infile1= <$infile>; close $infile; foreach my $dns ( @infile1 ) { chomp $dns; if ($dns =~ /(dns:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$ +/){ my ($ip, $dns1) = split /dns:/, $dns; ($ip) = split /,/, $dns1; print "$ip";} }
Perhaps you want something like this:
open my $infile, "<", "test.txt" or die "cannot open input: $!"; while ( my $dns = <$infile> ) { if ( $dns =~ /dns:([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) +/ ) { print "$1"; } } close $infile;
In reply to Re: Regex and splitting
by jwkrahn
in thread Regex and splitting
by astronogun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |