#!/usr/bin/perl use warnings; use strict; use Term::ReadKey; sub readInput { ReadMode(4); my $line = ""; my $key = " "; my $other_condition = 100; # 10 is the ord() of the newline character: while (ord($key) != 10) { # You can check for other conditions during input here: if ($other_condition != 100) { print "\n"; last; } while (not defined ($key = ReadKey(-1))) { } print $key; if (ord($key) != 10) { $line .= $key; } # $other_condition = 20; } ReadMode(0); return $line; } my $result = readInput(); print "Result is: $result\n";