use strict; use warnings; use Tk; use File::Util; my $mw = MainWindow->new(); my $fh = File::Util->new(); my $directory = ""; my $browse_button = $mw->Button( -text => "Browse", -command => sub { $directory = $mw->chooseDirectory( -mustexist => "true", ), }, )->pack(); my $save_button = $mw->Button( -text => "Save", -command => sub { $fh->make_dir( $directory, qw /--if-not-exists/ ); $fh->write_file( file => sprintf( "%s/text.txt", $directory ), content => "hello world", ); }, )->pack(); MainLoop;