in reply to Open a file of a different user

You could use sudo so that the account spawning the script has access to the file via sudo.

Or, you could use something like Expect. The code below would obviously have to be modified to fit what you're doing (e.g., we send $AWK, but $AWK is not defined), but it gives you a start:
#!/usr/bin/perl use strict; use warnings; use Expect; $TIMEOUT = 60; $USERNAME = '(hidden)'; $PASSWORD = '(hidden)'; $PROMPT = '%'; my $exp = new Expect; $exp->exp_internal(1); $exp->raw_pty(1); $exp->log_stdout(0); my $command = '/bin/su'; my @parameters = ( '-', $USERNAME ); $exp->spawn( $command, @parameters ) || die "cannot spawn \"$command:\ +" $!\n"; $exp->expect( $TIMEOUT, [ qr/password:\s*/i => sub { my $exp = shift; $exp->send($PASSWORD); exp_continue; } ], [ qr/$prompt/i => sub { my $exp = shift; $exp->send($AWK); exp_continue; } ], [ eof => sub { die "ERROR: could not spawn $command.\n"; } ], [ timeout => sub { die "Timed out.\n"; } ], ); $exp->soft_close(); exit(0);