my @ip while () { #assuming you are looping through a log file my $log = $_; #making this blatent push(@ip, $log) if $log =~ /^192\.168\.1\.10/;