my @commands = ( [ 'add_node', 'W1' ], [ 'add_node', 'W2' ], [ 'add_edge', 'W1', 'W2' ], ); use GraphViz; my $g = GraphViz->new(); foreach my $cur ( @commands ) { my $method = shift @{$cur}; $g->$method( @{ $cur } ); }