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/; #### push(@ip, $log) if 0 == index($log,'192.168.1.10');