Perl Cheat Sheet
Transform, format, and optimize your data instantly with this free client-side tool.
Basics
Declare a scalar variable
Declare an array
Declare a hash
Print to standard output
Print with automatic newline (needs 'use feature "say"')
Enforce strict scoping, variables declaration
Enable optional warnings
Scalars (Strings & Numbers)
Get string length
String concatenation
Convert string to uppercase / lowercase
Extract substring
Remove trailing newline
Arrays
Get array length (scalar context)
Access array element
Appends element to end of array
Removes and returns last element
Prepends element to beginning
Removes and returns first element
Sort array (string comparison)
Sort array numerically
Join array elements into string
Hashes
Access hash value
Get all keys of a hash
Get all values of a hash
Check if hash key exists
Remove key/value pair from hash
Control Structures
If statement (numeric comparison)
If statement (string comparison)
Else If
Execute block if condition is FALSE
For loop over range
Iterate over an array
Read filehandle line by line
Regular Expressions
Match regex pattern
Does not match pattern
Search and replace globally
Split string by regex
Subroutines
Define a subroutine
Call a subroutine
File I/O
Open file for reading
Open file for writing
Open file for appending
Read exactly one line
Slurp all lines into an array
Write to filehandle
Close filehandle
Advanced
Explore advanced configurations for Perl
Performance tuning best practices for Perl
Run security checks and validation for Perl
🔥 Similar Tools
Explore LibraryFrequently Asked Questions
Got questions? We've got answers.