while (defined(my $line = )) { if ($line =~ m/$pattern/) { printf "Port found: %d\n", (split $pattern, $line)[1]; } else { print "No Match\n"; } }