Since the key is always the last word on the line, you can get it by using split (which defaults to splitting on whitespace) and then index the resulting list with [-1] to get the last word (if any). You can then push the key onto an array for later use:
use strict;
use warnings;
use Data::Dump;
my $first = 'dev';
my $last = 'manage';
my $in = 0;
my @keys;
while (<DATA>)
{
if (defined(my $key = (split)[-1]))
{
if ($key eq $first .. $key eq $last)
{
$in = 1;
push @keys, $key;
}
elsif ($in && $key eq 'manage')
{
push @keys, $key;
}
else
{
$in = 0;
}
}
}
dd @keys;
__DATA__
< as before >
Output:
17:42 >perl 1916_SoPW.pl
(
"dev",
"dev",
"prod",
"prod",
"prod",
"qa",
"qa",
"qa",
"manage",
"manage",
"manage",
"manage",
)
17:42 >
Note: the defined test is needed only if the input file might contain blank lines.
Hope that helps,