# Some time later, changed the code to collect all the input "do { ... };", # not just the first line of STDIN. #!/usr/local/bin/perl use v5.26; use warnings; use Data::Dumper qw[ Dumper ]; use Getopt::Long; my $opt; GetOptions( 'opt:s' => \$opt ) or die $!; say Dumper( { 'Initial, opt' => $opt } ); if ( defined $opt ) { if ( -p STDIN ) { say q[Any option argument will be abandoned; collecting STDIN ...]; # Could process standard input line by line. # Here, all is collected at once. do { local $/; $opt = }; say Dumper( { ' ...after collecting STDIN, opt' => $opt } ); } elsif ( $opt eq '' ) { die qq[Neither a value was given for \$opt, nor was specified on standard input.]; } else { say qq[STDIN is not a pipe; using existing \$opt = $opt.]; } } else { say qq[\$opt was not used, so STDIN was ignored.]; } say Dumper( { 'Final, opt' => $opt } );