use warnings; use strict; open my $schedule, '<', 'Schedule'; my %schedule; $schedule{$_} = 1 while (<$schedule>); close $schedule; open my $wave, '>', 'Wave' or die "Can't open 'Wave': $!"; open my $keywords, '<', 'Agents' or die "Can't open 'Agents': $!"; open my $search_file, '<', 'Definitions' or die "Can't open 'Definitions': $!"; my $keyword_or = join '|', map {chomp; qr/\Q$_\E/} <$keywords>; my $regex = qr|\b($keyword_or)\b|; open my $schedule, '<', 'Schedule' or die "Can't open 'Schedule': $!"; while (defined (my $line = <$search_file>)) { while ($line =~ /$regex/g) { next if $line =~ /(SCRIPTNAME|DESCRIPTION)/; my $lineout = $line; chomp $lineout; print $wave $lineout; print $wave exists $schedule{$line} ? " | Yes \n" : " | No \n"; print $wave exists $schedule{$line} ? " | Yes \n" : " | No \n"; # at this point my output looks something like this: VALUE_FROM_SEARCH_FILE | Yes # want to use the value in $line as the input variable to the other script where marked as $value_from_line_in_search_file # want to print the result of other script back here # at this point I would like the output like this: VALUE_FROM_SEARCH_FILE | Yes | VALUE_FROM_SCHEDULE_FILE last; } } #### use warnings; use strict; my $value_from_line_in_search_file = 'SAMPLE#DATA'; open my $schedule, '<', 'Schedule' or die "Can't open 'Schedule': $!"; my @values=(); while (<$schedule>) { if (/(^SCHEDULE)(.*)/) { # SCHEDULE SCHEDULENAME, I only want the name. push(@values, $2); } if (/$value_from_line_in_search_file/) { print $values[-1]; last; } }