What others have posted already would be smarter than what I'm going to suggest. However, in the interests of contribution of all ideas, even ones that are fairly basic, here's another option:
my $group_name = 'monks';
my $gid = (split /:/, (grep /^$group_name:/, <GROUPS>));
print $gid, "\n";
Using getgrnam is a much better option, though. My way here assumes way too much and could therefore fail in many situations.
code('Perl') || die;