while (<>) { chomp; print collect( $_ ); } sub collect { local @ARGV = @_; join '', <>; } #### ls | perl ../perlmonks.pl #### file2 line1file1 line2file1 #### print collect( 'file1' ); print collect( 'file2' ); #### line1file1 line2file1 line1file2 line2file2
## ls | perl ../perlmonks.pl ##
## file2 line1file1 line2file1 ##
## print collect( 'file1' ); print collect( 'file2' ); ##
## line1file1 line2file1 line1file2 line2file2