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