open my $file_fh, '<', $file or die "unable to open $file for read : $!"; my $pattern = qr/ (?= .* fred \s+ (\w+) ) (?= .* barney \s+ (\w+) ) (?= .* joe \s+ (\w+) ) /ix; while ( my $line = <$file_fh> ) { if ( $line =~ /$pattern/ ) { $company = join '_', $1, $2, $3, 'inc';