$fn = 'glossary.pl'; $/ = ');'.$/; # cunning trick to read in the whole hash open (FILE, "<$fn"); while () { next unless (/%(\w+)(?:\s|=)/s); # match %word = or %word= push @hashnames, $1; } close(FILE);