in reply to Automatic Loop Counter not in perl

Another approach is to use an in-memory open (Perl 5.8.0+) thus enabling $.:
#!/usr/bin/perl use warnings; use strict; open (my $loop_fh, '<', \"Apples\nOranges\nBannanas\nKiwis") or die "unable to open: $!"; while (<$loop_fh>) { chomp; print "item $. is $_\n"; }