use autodie; use Path::Tiny; # read the file my $tpl= path("/home/vincent/.config/kmonad/$config")->slurp; # perform envsubst $tpl =~ s/\$ (?| (\w+) | \{(\w+)\} )/$ENV{$1}/gx; # open a pipe to a child process "kmonad" telling it to read from STDIN open(my $fh, "|-", "kmonad", "/dev/fd/0"); # Write the template to kmonad's stdin $fh->print($tpl); $fh->close;