#!/usr/bin/perl use strict; use warnings; my $total_sleep_time = 0; BEGIN { *CORE::GLOBAL::sleep = sub(@) { $total_sleep_time += CORE::sleep($_[0]); } } print "\$]=$] \$^V=$^V\n"; sleep(2); sleep(1); sleep(1.3); print "total sleep is $total_sleep_time\n"; $ time -p ./sleep.pl $]=5.024001 $^V=v5.24.1 total sleep is 4 real 4.00 user 0.00 sys 0.00