use strict; use warnings; my @recipient; open(my $file, "<", "input.txt") or die "Can't open input.txt: $!"; my $string = "hotmail\.com"; while (<$file>) { chomp; my $emailid= (split/\s+/,$_) [2]; if (/$string/) { print "found string $string:$emailid\n"; push(@recipient,$emailid); } else { print "did not find the string\n"; } }