$line =~ s/.*\]: //; #### $line =~ s/.*?\]: //; # note the ? following .* #### if ($line =~ /\[(\d+\.\d+\.\d+\.\d+)\].*Relay access denied/) { my $ip = $1; print "$ip\n"; }