isatty

Find out whether the process is controlled by a terminal:

use POSIX; 

my $flag_tty = POSIX::isatty( 'STDIN');