in reply to grep question using multiple lines

my $txt = <<'EOF'; f834bkg94halUF9deju hHFDUO()NFRS432 DSFadsfg94hHFDUO()N hfedls74d8oHFx constant=barney@gmail.com alUF9dejuH()NF UO()NFRS432 DSFadsf4halUF9deju fedls74d8oH sfg94hHFDUOf f834bkg94halUF9deju hHFDUO()NFRS432 DSFadsfg94hHFDUO()N hfedls74d8oHFx constant=wilma@aol.com alUF9dejuH()NFui0 UO()NFRS432 DSFadsf4halUF9deju fedls74d8oH sfg94hHFDUOf EOF while ($txt =~ /constant=(\w+@\w+\.\w+)/g) { print "$1\n"; }
Prints what you want for me. To understand what it does note the /g flag used to match that allows to not reset the match at the beginning from call to call as a result of the while loop.