my $run_cmd = "./tpsm -rules tpsm_rulesfile_ubuntu -looprf 0 -stop 10 -pspc 1 >logfile.txt "; # I extract logfile.txt from this string my ( $logfile ) = ( split />/,$run_cmd )[-1]; chomp($logfile); my $pagal = "$rundir_path/$logfile"; # this doesn't work-- case1 my $pagal = "$rundir_path/logfile.txt"; # this works fine -- case 2 open ( my $fh,"<",$pagal ) or die "No such logfile found\n";