$|=1; #autoflush sub spin { my @spinners = qw{/ - \ |}; my $index = $_[0]; print $spinners[$index]."\033[1D"; # man console_codes, ECMA-48 CSI sequences, "CUB" return $index == 3 ? 0 : $index++; } my $j=0; for (something) { do_something; $j=&spin($j); }