To implement it using your syntax you could do something like:
sub operate (&@) {
my $sub = shift;
local $~;
$~ = &$sub($_) for @_;
return $~
}
So for your examples you would get:
use strict;
sub operate (&@) {
my $sub = shift;
local $~;
$~ = &$sub($_) for @_;
return $~
}
my @list = (4, 6, 2, 67, 123, 645, 23, 54 );
my $max = operate { $~ > $_ ? $~ : $_ } @list;
print $max, "\n";
my $string = operate { $~.$_ } @list;
print $string, "\n";
open FILE, $0;
my $count = operate { $~ + /operate/ } <FILE>;
print "Count = $count\n";
And the results are
max = 645
string = 462671236452354
count = 4