use strict; use warnings; # Save standard output handle open(OLDOUT, ">&STDOUT"); # Reopen standard output as a pipe to the 'less' program open(STDOUT, "| /usr/bin/less") or die "$!\n"; # Output some stuff for (1..128) { print "Line: $_\n"; } # Close the modified STDOUT and reopen it as the original STDOUT again close(STDOUT); open(STDOUT, ">&OLDOUT") or die "Can't restore STDOUT: $!";