Perl implementation of Graph data structure