use strict; my $file = shift @ARGV; open (INPUT, "<$file"); my @ids = qw(1234 2345 3456); my %hash; foreach my $id (@ids) { while () { $hash{$id} = { headline => sub { return /.*headline: (.*)/ }, byline => sub { return /.*byline: (.*)/}, }; } print $hash{$id}->{byline}->()."\n"; } close INPUT;