get '/analysis' => sub { if (session('user') && session('logged_in')) { open FH, "<", "./scripts/test.out"; my $msg = ; close FH; chdir ("./scripts"); system("call sth"); #call external programs to generate a "test.png" my $err; copy ("test.png", "../public/images/test.png") || ($err = "cannot copy"); #copy the "test.png" to public/images directory, so the html tt can use it my $img = "test.png"; template 'analysis',{msg => $msg, img => $img, err => $err}; } else { return redirect '/' } };